
Originally Posted by
EmbersFire
Thanks for the link. I clearly need to do some more reading on this. You wouldn't happen to know how I would iterate through the child nodes to get the various property details?
Here I'm combining the first method I showed you on how to create an anonymous type with all of the relevant stuff from the Product node and combined it with the 2nd part where only the node with the PROPERTY_ID is included.
Code:
Dim propertyID = "PROPERTY_ID"
Dim theProd = (From prod In xdoc...<Product> _
.Where(Function(p) p...<Value> _
.Any(Function(prop) CStr(prop) = propertyID)) _
Select New With { _
.ID = prod.Attribute("ID").Value, _
.UserTypeID = prod.Attribute("UserTypeID").Value, _
.ParentID = prod.Attribute("ParentID").Value, _
.Name = prod.<Name>.Value, _
.AssetCrossReferences = (From acr In prod.<AssetCrossReference> _
Select New With { _
.AssetID = acr.Attribute("AssetID").Value, _
.AssetType = acr.Attribute("Type").Value _
}), _
.Values = (From vals In prod.<Values>.<Value> _
Select New With { _
.AttributeID = vals.Attribute("AttributeID").Value, _
.Description = vals.Value _
}) _
}).FirstOrDefault Just simply writing the details to a file so you can see how easy it is to loop through the AssetCrossReferences and Values collections created in the 1st step.
Code:
Using sw As New IO.StreamWriter("C:\temp\parsedItem.txt")
sw.WriteLine("ID: " & theProd.ID)
sw.WriteLine("User Type ID: " & theProd.UserTypeID)
sw.WriteLine("Parent ID: " & theProd.ParentID)
sw.WriteLine("Name: " & theProd.Name)
For Each acr In theProd.AssetCrossReferences
sw.WriteLine(ControlChars.Tab & "Asset ID: " & acr.AssetID)
sw.WriteLine(ControlChars.Tab & "Asset Type: " & acr.AssetType)
Next
For Each v In theProd.Values
sw.WriteLine(ControlChars.Tab & "Attribute ID: " & v.AttributeID)
sw.WriteLine(ControlChars.Tab & "Description: " & v.Description)
Next
End Using
Bookmarks