Jump to content

xml issues


Champak
 Share

Recommended Posts

I'm having issues retrieving xml data and would appreciate some help. I know I can use stringbetween, that's how I currently have it set up, but I would prefer to code it using xml udf. Thanks.

Here is my xml

<?xml version="1.0" encoding="UTF-8"?>

-<Response xmlns="http://schemas.microsoft.com/search/local/ws/rest/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<Copyright>Copyright © 2015 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.</Copyright>

<BrandLogoUri>http://dev.virtualearth.net/Branding/logo_powered_by.png</BrandLogoUri>

<StatusCode>200</StatusCode>

<StatusDescription>OK</StatusDescription>

<AuthenticationResultCode>ValidCredentials</AuthenticationResultCode>

<TraceId>ba045015415e4fcc9027134c597c32db|BN20130730|02.00.118.2700|BN20010757</TraceId>


-<ResourceSets>


-<ResourceSet>

<EstimatedTotal>12</EstimatedTotal>


-<Resources>


-<TrafficIncident>


-<Point>

<Latitude>40.66064</Latitude>

<Longitude>-73.82395</Longitude>

</Point>

<Source>4</Source>

<IncidentId>1832471649336352436</IncidentId>

<LastModifiedUTC>2015-11-18T19:13:02.3239431Z</LastModifiedUTC>

<StartTimeUTC>2015-11-16T17:47:47Z</StartTimeUTC>

<EndTimeUTC>2016-03-01T04:50:00Z</EndTimeUTC>

<Type>Construction</Type>

<Severity>Serious</Severity>

<Verified>true</Verified>

<RoadClosed>true</RoadClosed>

<Description>Closed between Lefferts Blvd and 130th Pl - Closed due to roadwork.</Description>


-<ToPoint>

<Latitude>40.66107</Latitude>

<Longitude>-73.81183</Longitude>

</ToPoint>

</TrafficIncident>


-<TrafficIncident>


-<Point>

<Latitude>40.70599</Latitude>

<Longitude>-74.0052</Longitude>

</Point>

<Source>4</Source>

<IncidentId>642941875063101946</IncidentId>

<LastModifiedUTC>2015-11-16T21:56:51.9523935Z</LastModifiedUTC>

<StartTimeUTC>2015-11-16T17:47:46Z</StartTimeUTC>

<EndTimeUTC>2016-01-01T04:50:00Z</EndTimeUTC>

<Type>Construction</Type>

<Severity>Serious</Severity>

<Verified>true</Verified>

<RoadClosed>true</RoadClosed>

<Description>Closed between Front St and South St - Closed due to roadwork.</Description>


-<ToPoint>

<Latitude>40.70541</Latitude>

<Longitude>-74.00445</Longitude>

</ToPoint>

</TrafficIncident>

</Resources>

</ResourceSet>

</ResourceSets>

</Response>

Here is my code

#include <_XMLDomWrapper.au3>

            $Xml = _XMLFileOpen("http://dev.virtualearth.net/REST/v1/Traffic/Incidents/40.590923,-73.564859,41.145923,-74.119859?&output=xml&key=DELETED")
ConsoleWrite("+ " & $Xml & @CRLF)


            $count = _XMLGetNodeCount ("//Response/ResourceSets/ResourceSet/Resources/TrafficIncident/*")
ConsoleWrite("> " & $count & @CRLF)


            $XmlLat = _XMLGetValue ("//Response/ResourceSets/ResourceSet/Resources/TrafficIncident/Point/Latitude")
ConsoleWrite("! " & $XmlLat & @CRLF)

 

Edited by Champak
Link to comment
Share on other sites

$sXML = FileRead("your.xml")

Local $oXML = ObjCreate("Microsoft.XMLDOM")
$oXML.loadxml($sXML)
$oIncidents = $oXML.SelectNodes("//Response/ResourceSets/ResourceSet/Resources/TrafficIncident")

For $oIncident In $oIncidents
    $oLatitude = $oIncident.SelectSingleNode("./Point/Latitude")
    ConsoleWrite($oLatitude.text & @CRLF)
Next

 

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

figured it out

$sXML = "http://dev.virtualearth.net/REST/v1/Traffic/Incidents/40.590923,-73.564859,41.145923,-74.119859?&output=xml&key=DELETED"

Local $oXML = ObjCreate("Microsoft.XMLDOM")
$oXML.async = False
$oXML.load($sXML)
$oIncidents = $oXML.SelectNodes("//Response/ResourceSets/ResourceSet/Resources/TrafficIncident")
;ConsoleWrite($oXML.parseError.reason & @LF)

For $oIncident In $oIncidents

    $oLatitude = $oIncident.SelectSingleNode("./Point/Latitude")
    $oLongitude = $oIncident.SelectSingleNode("./Point/Longitude")
    ConsoleWrite($oLatitude.text & ", ")
    ConsoleWrite($oLongitude.text & @CRLF)
Next

Actual bing key deleted so this wont work, but this is an example for anyone else.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...