Re: [xml] Question about 'text' elements



"Martin" == Martin Craig <m s craig rl ac uk> writes:

    Martin> Hi, I've read the FAQ & understand why libxml2 adds text
    Martin> elements for docs containing whitespace, e.g.

    Martin> <tag1>
    Martin>   <tag2>hi</tag2>
    Martin> </tag1>

    Martin> gets parsed to

    Martin> <tag1><text>
    Martin>   </text><tag2>, etc...

    Martin> However I don't understand why

    Martin> <URI>d2925.restart2.hdf</URI>

    Martin> gets parsed to

    Martin> <URI><text>d2925.restart2.hdf</text></URI>

    Martin> Is this really correct behaviour? (I'm not an XML expert
    Martin> so it may well be correct but it seems very bizarre).

"Adding a text element" does not mean adding a tag <text>...</text>.
What is meant is that the text (only whitespace in this case) between
tag1 and tag2 is returned by the parser as being text consisting of a
newline and two spaces and thus is not being ignored. 

So 

   <URI>d2925.restart2.hdf</URI> 

consists of:
         
    * an element with name "URI"
    * a text element with value "d2925.restart2.hdf"
    
and 

    <URI><text>d2925.restart2.hdf</text></URI>

consists of:
         
    * an element with name "URI"
    * an element with name "text"
    * a text element with value "d2925.restart2.hdf"


Maybe looking at the figure shown at 

    http://www.xmlsoft.org/tree.html

will show some insight.


Does this answer your question?

Geert



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]