I've managed to work out how to get to everything on this xml file, but these parts. I cannot for the life of me figure out what i need to do. Any help or pointers would be great, Im using VB6. I want a way to get hold of the data (BUL-BUlletin) in Value="BUL - Bulletin" as below.
<?xml version="1.0" encoding="UTF-8" ?> <NewsML> <Catalog Href="" /> <NewsEnvelope> <NewsItem> <Identification> <NewsManagement> <NewsComponent> <DescriptiveMetadata> <Language FormalName="en-GB" /> <OfInterestTo FormalName="all" /> <Property FormalName="Category" Value="BUL - Bulletin" /> </DescriptiveMetadata> <ContentItem> </NewsComponent> </NewsItem> </NewsML>
The SearchForAttribute method is good if you don't know where the attribute is located within the XML document. However, it can be expensive because it's traversing the XML document looking for it..
If you already know the exact location of what you need to get, then ChilkatPath is best:
Dim x As New ChilkatXml x.LoadXml(App.Path & "600002.xml") MsgBox x.ChilkatPath("NewsML|NewsEnvelope|NewsItem|Identification|NewsManagement|NewsComponent|DescriptiveMetadata|Property|(Value)")
answered Mar 14 '16 at 21:03
Thank you jpbro. Just had to tweak it as object variable or with variable not set - error 91.
But thank you for pointing me to the answer, really appreciated.
FYI Just changed to this to avoid the error. Dim x As New ChilkatXml MsgBox x.LoadXml(App.Path & "600002.xml") MsgBox x.SearchForAttribute(x.GetRoot, "Property", "Value", "*").GetAttrValue("Value")
answered Mar 14 '16 at 18:39
This seems to work:
Dim lo_Xml As Chilkat_v9_5_0.ChilkatXml Set lo_Xml = New ChilkatXml If lo_Xml.LoadXML("C:\test.xml") = 1 then Debug.Print lo_Xml.SearchForAttribute(lo_Xml.GetRoot, "Property", "Value", "*").GetAttrValue("Value") End If
Side note - it looks like your XML is invalid - there's no closing tags for Identification, NewsManagement or ContentItem. Not sure if this will cause adverse effects or not.