B4J Question XML Parser, Node Query...

vfafou

Well-Known Member
Licensed User
Longtime User
Hello!
Is there any way to query nodes from xml like Microsoft XML?
B4X:
NodeLst = sXML.SelectNodes("//RouteSegment[@name=""Route Point 3""]")
If Not (aNodeLst Is Nothing) Then
            For Each aNode In aNodeLst
                For Each aAttr In aNode.Attributes
                    If aAttr.baseName = "totalDistance" Then
                        RouteDist = Round(Val(aAttr.Text) * 1000, 2)
                    End If
                Next
            Next
        End If
The full XML format is:
B4X:
<RouteResponse>
<RouteResult routeId="1">
   <RouteSegment order="1" name="Route Point 1" time="" totalTime="" distance=""
                 totalDistance="0.0" speed="" turn="" turnPointX=""
                 turnPointY="" segments="" turnSegments=""/>
   <RouteSegment order="2" name="Route Point 2" time="" totalTime="" distance=""
                 totalDistance="21.7" speed="" turn="" turnPointX=""
                 turnPointY="" segments="" turnSegments=""/>
   <RouteSegment order="3" name="Route Point 3" time="" totalTime="" distance=""
                 totalDistance="34.5" speed="" turn="" turnPointX=""
                 turnPointY="" segments="" turnSegments=""/>
  </RouteResult>
</RouteResponse/>
I need to take the totalDistance="34.5" from <RouteSegment order="3" name="Route Point 3"...

Thank you in advance!
 
Last edited:

vfafou

Well-Known Member
Licensed User
Longtime User
Oh... Erel, I've made a terrible mistake!
The server responds with the following:
B4X:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns="urn:MapServerIntf-INGIMapServer"><soap:Body><ns:RouteResponse soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><return xsi:type="xs:int">1</return>
<RouteResponse xsi:type="xs:string">&#60;?xml version=&#34;1.0&#34; encoding=&#34;windows-1253&#34;?&#62; &#60;RouteResponse&#62;&#60;RouteResult routeId=&#34;1&#34; routingFunctionTime=&#34;0.5&#34;&#62;&#60;RouteSegments&#62;&#60;RouteSegment order=&#34;1&#34; name=&#34;Route Point 1&#34; time=&#34;0.00&#34; totalTime=&#34;0.00&#34; distance=&#34;0.00&#34; totalDistance=&#34;0.00&#34; speed=&#34;0.00&#34; turn=&#34;-1.00&#34; turnPointX=&#34;19.512485&#34; turnPointY=&#34;0.002229&#34; isInputPoint=&#34;1&#34;/&#62;&#60;RouteSegment order=&#34;2&#34; name=&#34; &#34; time=&#34;33.50&#34; totalTime=&#34;33.50&#34; distance=&#34;18.95&#34; totalDistance=&#34;18.95&#34; speed=&#34;34.00&#34; turn=&#34;-2.00&#34; turnPointX=&#34;23.652920&#34; turnPointY=&#34;37.984108&#34; isInputPoint=&#34;0&#34;/&#62;&#60;RouteSegment order=&#34;3&#34; name=&#34;Route Point 2&#34; time=&#34;0.00&#34; totalTime=&#34;33.50&#34; distance=&#34;0.00&#34; totalDistance=&#34;18.95&#34; speed=&#34;0.00&#34; turn=&#34;-3.00&#34; turnPointX=&#34;19.512485&#34; turnPointY=&#34;0.002229&#34; isInputPoint=&#34;1&#34;/&#62;&#60;/RouteSegments&#62;&#60;RouteOrder&#62;&#60;RoutePoint pointX=&#34;23.790568&#34; pointY=&#34;38.059146&#34; description=&#34;Route Point 1&#34; timeToStay=&#34;0.00&#34;/&#62;&#60;RoutePoint pointX=&#34;23.652920&#34; pointY=&#34;37.984108&#34; description=&#34;Route Point 2&#34; timeToStay=&#34;0.00&#34;/&#62;&#60;/RouteOrder&#62;&#60;/RouteResult&#62;&#60;/RouteResponse&#62; </RouteResponse></ns:RouteResponse></soap:Body></soap:Envelope>
How could I separate from this response the following I'm interested in?
B4X:
&#60;?xml version=&#34;1.0&#34; encoding=&#34;windows-1253&#34;?&#62; &#60;RouteResponse&#62;&#60;RouteResult routeId=&#34;1&#34; routingFunctionTime=&#34;0.5&#34;&#62;&#60;RouteSegments&#62;&#60;RouteSegment order=&#34;1&#34; name=&#34;Route Point 1&#34; time=&#34;0.00&#34; totalTime=&#34;0.00&#34; distance=&#34;0.00&#34; totalDistance=&#34;0.00&#34; speed=&#34;0.00&#34; turn=&#34;-1.00&#34; turnPointX=&#34;19.512485&#34; turnPointY=&#34;0.002229&#34; isInputPoint=&#34;1&#34;/&#62;&#60;RouteSegment order=&#34;2&#34; name=&#34; &#34; time=&#34;33.50&#34; totalTime=&#34;33.50&#34; distance=&#34;18.95&#34; totalDistance=&#34;18.95&#34; speed=&#34;34.00&#34; turn=&#34;-2.00&#34; turnPointX=&#34;23.652920&#34; turnPointY=&#34;37.984108&#34; isInputPoint=&#34;0&#34;/&#62;&#60;RouteSegment order=&#34;3&#34; name=&#34;Route Point 2&#34; time=&#34;0.00&#34; totalTime=&#34;33.50&#34; distance=&#34;0.00&#34; totalDistance=&#34;18.95&#34; speed=&#34;0.00&#34; turn=&#34;-3.00&#34; turnPointX=&#34;19.512485&#34; turnPointY=&#34;0.002229&#34; isInputPoint=&#34;1&#34;/&#62;&#60;/RouteSegments&#62;&#60;RouteOrder&#62;&#60;RoutePoint pointX=&#34;23.790568&#34; pointY=&#34;38.059146&#34; description=&#34;Route Point 1&#34; timeToStay=&#34;0.00&#34;/&#62;&#60;RoutePoint pointX=&#34;23.652920&#34; pointY=&#34;37.984108&#34; description=&#34;Route Point 2&#34; timeToStay=&#34;0.00&#34;/&#62;&#60;/RouteOrder&#62;&#60;/RouteResult&#62;&#60;/RouteResponse&#62;
 
Upvote 0
Top