how to parse such XML

peacemaker

Expert
Licensed User
Longtime User
Hi, Erel or any profi,

Please, suggest how to parse such text.

B4X:
   Dim tr As TextReader
   tr.Initialize2(HttpUtils.GetInputStream(Url),"UTF8")
   Try
   XML.Parse2(tr, "Parser")

As string all is downloaded correct, but Sub Parser_EndElement returns only parent NAMEs, but TEXT is always empty, how to get fields with quoted values ?:

B4X:
<answer>
<error/>
<result>
<root>
<server time="2012-05-21 11:35:07 +0000"/>
<managers>
<manager name="Bedroom" desc="" id="382" type="1" eip="85.236.174.66"iip="192.168.1.111" mac="88-B6-27-01-00-01" lts="2011-12-15 10:19:24 +0000">
<socket name="Socket1" s="0"/>
<socket name="Socket2" s="1"/>
<socket name="Socket3" s="1"/>
<socket name="Socket4" s="0"/>
</manager>
<manager name="Device4" desc="" id="520" type="2" eip="112.95.145.165"iip="192.168.16.102" mac="00-11-F6-8B-D2-A7" lts="2011-12-16 03:54:21 +0000">
<socket name="Socket1" s="1"/>
<socket name="Socket2" s="0"/>
<socket name="Socket3" s="0"/>
<socket name="Socket4" s="0"/>
</manager>
<manager name="Device5" desc="" id="524" type="2" eip="112.95.145.165"iip="192.168.1.100" mac="00-11-F6-8B-D2-A6" lts="2011-12-14 09:37:46 +0000">
<socket name="Socket1" s="0"/>
<socket name="Socket2" s="1"/>
<socket name="Socket3" s="1"/>
<socket name="Socket4" s="1"/>
</manager>
<manager name="Device5" desc="" id="533" type="1" eip="112.95.145.165"iip="192.168.1.108" mac="88-B6-27-01-00-10" lts="2011-12-19 03:44:20 +0000">
<socket name="Socket1" s="0"/>
<socket name="Socket2" s="0"/>
<socket name="Socket3" s="1"/>
<socket name="Socket4" s="1"/>
</manager>
</managers>
<meters>
<meter name="Television" desc="" id="54" type="3" eip="85.236.174.66"iip="192.168.1.107" mac="88-B6-27-01-00-05" lts="2012-05-17 12:14:29 +0000"/>
<meter name="Device6" desc="" id="601" type="3" eip="82.148.198.99"iip="192.168.2.51" mac="88-B6-27-01-00-11" lts="2012-05-12 07:33:43 +0000">
<measure name="Power" v="0"/>
<measure name="Energy (Day)" v="10.1605224609375"/>
<measure name="Energy (Night)" v="0"/>
</meter>
</meters>
</root>
</result>
</answer>
 

warwound

Expert
Licensed User
Longtime User
If i copy and paste your XML to file and load it in Firefox i get this error:

XML Parsing Error: not well-formed
Location: file:///U:/martin/Desktop/test.xml
Line Number 7, Column 70:<manager name="Bedroom" desc="" id="382" type="1" eip="85.236.174.66"iip="192.168.1.111" mac="88-B6-27-01-00-01" lts="2011-12-15 10:19:24 +0000">

The error being no space between the end of the eip attributes and the start of the iip attributes:

B4X:
eip="112.95.145.165"iip="192.168.1.108"

Should be:

B4X:
eip="112.95.145.165" iip="192.168.1.108"

That might just be an error introduced by posting it on the forum - the original XML might not have that error - but check it out anyway, it might be relevant.

Martin.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
<answer><error></error><result><root><server time="2012-05-24 19:38:00 +0000" /><managers><manager name="Bedroom" desc="" id="382" type="1" eip="85.236.174.66" iip="192.168.1.111" mac="88-B6-27-01-00-01" lts="2011-12-15 10:19:24 +0000"><socket name="Socket1" s="0" /><socket name="Socket2" s="1" /><socket name="Socket3" s="1" /><socket name="Socket4" s="0" /></manager><manager name="Device4" desc="" id="520" type="2" eip="112.95.145.165" iip="192.168.16.102" mac="00-11-F6-8B-D2-A7" lts="2011-12-16 03:54:21 +0000"><socket name="Socket1" s="1" /><socket name="Socket2" s="0" /><socket name="Socket3" s="0" /><socket name="Socket4" s="0" /></manager><manager name="Device5" desc="" id="524" type="2" eip="112.95.145.165" iip="192.168.1.100" mac="00-11-F6-8B-D2-A6" lts="2011-12-14 09:37:46 +0000"><socket name="Socket1" s="0" /><socket name="Socket2" s="1" /><socket name="Socket3" s="1" /><socket name="Socket4" s="1" /></manager><manager name="Device5" desc="" id="533" type="1" eip="112.95.145.165" iip="192.168.1.108" mac="88-B6-27-01-00-10" lts="2011-12-19 03:44:20 +0000"><socket name="Socket1" s="0" /><socket name="Socket2" s="0" /><socket name="Socket3" s="1" /><socket name="Socket4" s="1" /></manager></managers><meters><meter name="Television" desc="" id="54" type="3" eip="85.236.174.66" iip="192.168.1.107" mac="88-B6-27-01-00-05" lts="2012-05-17 12:14:29 +0000" /><meter name="Device6" desc="" id="601" type="3" eip="82.148.198.99" iip="192.168.2.51" mac="88-B6-27-01-00-11" lts="2012-05-12 07:33:43 +0000"><measure name="Power" v="0" /><measure name="Energy (Day)" v="10.1605224609375" /><measure name="Energy (Night)" v="0" /></meter></meters></root></result></answer>


original text, non-formatted.
And sure - i'm trying to parse directly after downloading, so spaces are OK between params.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Solved. Here those elements are Attributes of the StartElement.
 
Upvote 0
Top