Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2006

Tip: Looking for answers? Try searching our database.

Java reading XML files containing long values

Thread view: 
JimmyB - 02 Feb 2006 20:36 GMT
In C you can write something like this

#define something = "döaslkdasö" \
                             "djalkjddlasdj" \
                             "asdölasköla" \
                             "ädadassdlö"

to prevent long definitions in one big line,  not writing a long clause
like:
#define something = "döaslkdasö djalkjddlasdj asdölasköla lasödla ölaskdölas
ölaskdöal"

So, is it possible to write that kind of long values or XML tag sentences
into XML file and read them in Java application as a whole row?

I mean something like this:

<myKey = "<tag> this is a veeeeeeeeery " +
                 " loooooooooong sentence or value " +
                 "</tag>"

Cheers,
Oliver Wong - 02 Feb 2006 20:48 GMT
> In C you can write something like this
>
> #define something = "döaslkdasö" \
>                              "djalkjddlasdj" \
>                              "asdölasköla" \
>                              "ädadassdlö"

   Is this legal C? Wouldn't you need some sort of concatenation operator
between each string?

> to prevent long definitions in one big line,  not writing a long clause
> like:
[quoted text clipped - 10 lines]
>                  " loooooooooong sentence or value " +
>                  "</tag>"

   This would be legal Java except for the fact that "<myKey" is not a
legal identifier. If you rename it "myKey", it should work, assuming myKey
can be assigned a string.

   However, maybe I'm completely misunderstanding you, because the subject
of this post talks about *reading* XML, but you seem be *writing* strings.

   - Oliver
Roedy Green - 02 Feb 2006 21:13 GMT
>> #define something = "döaslkdasö" \
>>                              "djalkjddlasdj" \
[quoted text clipped - 3 lines]
>    Is this legal C? Wouldn't you need some sort of concatenation operator
>between each string?

in C it is as if the line breaks were not there. So you don't need an
operator.

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Oliver Wong - 02 Feb 2006 22:12 GMT
>>> #define something = "döaslkdasö" \
>>>                              "djalkjddlasdj" \
[quoted text clipped - 6 lines]
> in C it is as if the line breaks were not there. So you don't need an
> operator.

   I'm aware of the usage of \ to "escape" line breaks, but wouldn't code
like:

<C code>
something = "a" \
    "b"
</C code>

   be seen by the compiler (after the pre-processor has had its way with
it) as:

<C code>
something = "a"     "b"
</C code>

   Or does the \ actually remove the white space indendation and pairs of
quotation marks as well?

   - Oliver
~Glynne - 03 Feb 2006 20:26 GMT
> >>> #define something = "döaslkdasö" \
> >>>                              "djalkjddlasdj" \
[quoted text clipped - 21 lines]
> something = "a"     "b"
> </C code>

Yes.

>     Or does the \ actually remove the white space indendation and pairs of
> quotation marks as well?
The C compiler concatenates adjacent string literals into a single
string literal....but this "trick" will not work at run time, i.e. with
string variables.

~Glynne
Roedy Green - 02 Feb 2006 21:12 GMT
>I mean something like this:
>
><myKey = "<tag> this is a veeeeeeeeery " +
>                  " loooooooooong sentence or value " +
>                  "</tag>"

I think in XML \n is treated as if it were space. At least that is how
its relatives work.  That still does not give you a way of breaking up
a long string without embedded spaces.

One practical way of handling the situation would be on parsing the
file to compact the strings to get to get rid of junk whitespace
introduced through transport with XML.

/**
    * Remove all spaces from a String. see also condense .
    *
    * @param s
    *        String to strip of blanks.
    * @return String with all blanks, lead/trail/embedded removed.
    */
   public static String squish ( String s )
       {
       if ( s == null )
           {
           return null;
           }
       s = s.trim();
       if ( s.indexOf( ' ' ) < 0 )
           {
           return s;
           }
       int len = s.length();
   
       StringBuilder b = new StringBuilder( len - 1 );
       for ( int i = 0; i < len; i++ )
           {
           char c = s.charAt( i );
           if ( c != ' ' )
               {
               b.append( c );
               }
           } // end for
       return b.toString();
       } // end squish

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

JimmyB - 03 Feb 2006 17:32 GMT
Thanks Roedy!
A good point that gives me new ideas.
Cheers!

>>I mean something like this:
>>
[quoted text clipped - 41 lines]
>        return b.toString();
>        } // end squish


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.