Question Query XML

gchq

Well-known member
Joined
Dec 14, 2007
Messages
168
Programming Experience
10+
I am attempting to return the value for "productID" (850352) from the following XML where "locName" (6576) is supplied in the query.

Any help would be appreciated....


VB.NET:
<?xml version="1.0" encoding="UTF-16"?>
-<vps> 
-<vendorProductSets> 
-<vendorProductSet version="1" vendorID="81" copyright="Copyright 2006 Avery Dennison Corp., all rights reserved" 
schemaVersion="1" vendor="Avery US Letter"> 
-<product productID="850352" bindingEdge="none" units="emu" layoutGroup="otherLabel"> 
-<prodName nameGroup="custom"> 
<locName locale="all">6576</locName> 
</prodName> 
-<desc descGroup="custom"> 
<locDesc locale="es">Etiquetas de identificación perdurables</locDesc> 
<locDesc locale="fr">Étiquettes durables</locDesc> 
<locDesc locale="allOthers">Durable ID Labels</locDesc> 
</desc> 
<masterPanel centerContent="true" topMargin="91440" rightMargin="91440" leftMargin="91440" bottomMargin="91440" cornerRadius="85725" shape="rect" width="1600200" height="1143000" masterID="0"/> 
-<sheet width="7772400" height="10058400"> 
<sheetGrid numDown="8" numAcross="4" vertGap="0" horizGap="171907" cellWidth="1600200" cellHeight="1143000" posY="457200" posX="428854"/> </sheet> 
</product>
 
Sorted it

Although I have to say if you don't know how many nodes deep I would be lost again....

VB.NET:
Dim vXML As XDocument = XDocument.Load(System.Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) & "\Microsoft Office\Office12\PAGESIZE\PGLBL081.XML")
            Dim Query = From xe In vXML.Descendants("product") Where xe.<prodName>.<locName>.Value = Label_Name Select xe.Attribute("productID").Value
            If Not Query Is Nothing Then
                LabelID = CType(Query(0), Int64)
            End If
 
Back
Top