Jump to content
chaoticyeshua

Help Parsing XML

Recommended Posts

chaoticyeshua

Hi all,

I am needing some assistance with parsing some XML code. The purpose of this is to pull warranty information for Dell computers I support. I am needing only the EndDate value on the first AssetEntitlement node, and unfortunately I cannot seem to get _XMLDomWrapper to work. The below code works to read in the XML file and list the child nodes:

AdditionalInformation
AssetWarrantyResponse
ExcessTags
InvalidBILAssets
InvalidFormatAssets

Unfortunately, I can't figure out how to read anything at all below each of the above child nodes. I'm very unfamiliar with how to parse XML files.

;Create a Microsoft XML HTTP object
Local $oXML = ObjCreate("Microsoft.XMLHTTP")

;Open a connection to the Dell REST API to pull the warranty information. This returns XML code
$oXML.Open("GET", "https://api.dell.com/support/assetinfo/v4/getassetwarranty/" & GUICTRLRead($iSerialNumber) & "?apikey=XXXXXXXXXXXXXXXXXXXXXXXXXX", 0)
$oXML.SetRequestHeader("Accept", "Application/xml")
$oXML.Send

;Create a file in temp with the returned XML code
$sFile = _TempFile(@TempDir, '~', '.xml')
FileWrite($sFile, $oXML.responseText)

If _XMLFileOpen($sFile) Then
    Local $aRet = _XMLGetChildNodes('//*')

    If Not @error Then
        For $i = 1 To $aRet[0]
            ConsoleWrite($aRet[$i] & @LF)
        Next
    EndIf
EndIf

 

XML:

<AssetWarrantyDTO xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/Dell.Support.AssetsExternalAPI.Web.Models.V1.Response">
<AdditionalInformation i:nil="true"/>
<AssetWarrantyResponse>
<AssetWarrantyResponse>
<AssetEntitlementData>
<AssetEntitlement>
<EndDate>2018-07-13T23:59:59</EndDate>
<EntitlementType>INITIAL</EntitlementType>
<ItemNumber>997-7188</ItemNumber>
<ServiceLevelCode>ND</ServiceLevelCode>
<ServiceLevelDescription>
Onsite Service After Remote Diagnosis (Consumer Customer)/ Next Business Day Onsite After Remote Diagnosis (Commercial Customer)
</ServiceLevelDescription>
<ServiceLevelGroup>5</ServiceLevelGroup>
<ServiceProvider>UNY</ServiceProvider>
<StartDate>2015-07-13T00:00:00</StartDate>
</AssetEntitlement>
<AssetEntitlement>
<EndDate>2018-07-13T23:59:59</EndDate>
<EntitlementType>INITIAL</EntitlementType>
<ItemNumber>984-1772</ItemNumber>
<ServiceLevelCode>KK</ServiceLevelCode>
<ServiceLevelDescription>Keep Your Hard Drive Service</ServiceLevelDescription>
<ServiceLevelGroup>11</ServiceLevelGroup>
<ServiceProvider>DELL</ServiceProvider>
<StartDate>2015-07-13T00:00:00</StartDate>
</AssetEntitlement>
<AssetEntitlement>
<EndDate>2018-07-13T23:59:59</EndDate>
<EntitlementType>INITIAL</EntitlementType>
<ItemNumber>997-7208</ItemNumber>
<ServiceLevelCode>TS</ServiceLevelCode>
<ServiceLevelDescription>ProSupport</ServiceLevelDescription>
<ServiceLevelGroup>8</ServiceLevelGroup>
<ServiceProvider>DELL</ServiceProvider>
<StartDate>2015-07-13T00:00:00</StartDate>
</AssetEntitlement>
</AssetEntitlementData>
<AssetHeaderData>
<BUID>11</BUID>
<CountryLookupCode>US</CountryLookupCode>
<CustomerNumber>142366234</CustomerNumber>
<IsDuplicate>false</IsDuplicate>
<ItemClassCode>J2002</ItemClassCode>
<LocalChannel>65</LocalChannel>
<MachineDescription>Precision Tower Workstation (T5810)</MachineDescription>
<OrderNumber>852696778</OrderNumber>
<ParentServiceTag i:nil="true"/>
<ServiceTag>XXXXXX</ServiceTag>
<ShipDate>2015-07-13T00:00:00</ShipDate>
</AssetHeaderData>
<ProductHeaderData>
<LOB>Dell Precision WorkStation</LOB>
<LOBFriendlyName>Precision WorkStation</LOBFriendlyName>
<ProductFamily>Desktops & All-in-Ones</ProductFamily>
<ProductId>precision-t5810-workstation</ProductId>
<SystemDescription>Precision Tower Workstation (T5810)</SystemDescription>
</ProductHeaderData>
</AssetWarrantyResponse>
</AssetWarrantyResponse>
<ExcessTags>
<BadAssets xmlns:d3p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
</ExcessTags>
<InvalidBILAssets>
<BadAssets xmlns:d3p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
</InvalidBILAssets>
<InvalidFormatAssets>
<BadAssets xmlns:d3p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
</InvalidFormatAssets>
</AssetWarrantyDTO>

 

Any help would be greatly appreciated!!

Share this post


Link to post
Share on other sites
chaoticyeshua

Never mind, I just found the updated version of _XMLDomWrapper at 

This has example code for how to do what I'm needing to do so I will try to figure it out on my own :) Thanks

Share this post


Link to post
Share on other sites
mikell

@chaoticyeshua

As an alternative you might simply extract the wanted data from the response using a regular expression  :)

$txt = $oXML.responseText
$sEndDate = StringRegExpReplace($txt, '(?s).*?<EndDate>([^<]+).*', "$1")

 

  • Like 1

Share this post


Link to post
Share on other sites
chaoticyeshua
9 hours ago, mikell said:

@chaoticyeshua

As an alternative you might simply extract the wanted data from the response using a regular expression  :)

$txt = $oXML.responseText
$sEndDate = StringRegExpReplace($txt, '(?s).*?<EndDate>([^<]+).*', "$1")

 

Thank you for the advice. I ended up resolving this by using XML.au3's tidy function to clean up the XML file downloaded from Dell, then reading the file into an array and finding the data I need using StringInStr.

Share this post


Link to post
Share on other sites
jdelaney

When what you are looking for is more complex, post the problem, and someone will show you how the xpaths work to find whatever it is.


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.

Share this post


Link to post
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

×