Re: [xml] xmlTextReaderLocalName returns #text



On Sat, Jan 2, 2010 at 7:07 PM, Michael Andersson
<anderssonmichael hotmail com> wrote:
Hi!
I'm having trubble reading my xml file when they contain newline characters.
The problem is that when I call xmlTextReaderLocalName it returns #text
instead of the element name. This is what my xml file looks like:
<?xml version="1.0" encoding="UTF-8"?>
<TestType>
<int8 type="int8">-126</int8>
<uint8 type="uint8">249</uint8>
<int16 type="int16">-31010</int16>
<uint16 type="uint16">65211</uint16>
<int32 type="int32">-2147483640</int32>
<uint32 type="uint32">4294967290</uint32>
<int64 type="int64">-9223372036854775805</int64>
<uint64 type="uint64">9223372036854775804</uint64>
<float32 type="float">1598</float32>
<float64 type="float64">3489</float64>
<string type="string">&quot;This is a string&quot;</string>
</TestType>
If I remove all the newline characters and put everything on the same line
my program can read the xml file.
Any ideas what the problem could be?

There is no problem, you just need to move a bit further ahead in the XML.
Those newline characters appear as nodes of type XML_READER_TYPE_TEXT
(or maybe XML_READER_TYPE_SIGNIFICANT_WHITESPACE). Those nodes always
have name="#text"

So, between

XML_READER_TYPE_ELEMENT, name=TestType
and
XML_READER_TYPE_ELEMENT, name=int8
there is a node
XML_READER_TYPE_SIGNIFICANT_WHITESPACE, name=#text, value=(newline)

If you want to process elements, you need to check
xmlTexReaderNodeType and skip nodes which aren't
XML_READER_TYPE_ELEMENT.

Hope this helps,
Csaba
-- 
Life is complex, with real and imaginary parts



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