Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading XML in VB

Status
Not open for further replies.

GDX

Programmer
Jun 4, 2000
186
US
Lets say i have an xml page setup...

<book>Mybook</book>
<price>$5</price>

how do i go about &quot;reading&quot; this information into a visual basic application? basically what i want to do is have the clients use the application and read the xml page, so when i add more information all they have to do is run the application :)

Thanking you in advance,
Gordon R. Durgha

Gordon R. Durgha
gd@vslink.net


Gordon R. Durgha
gd@vslink.net
 
GDX,
I have the same problem. Did you ever get this question answered?
Mathprof
 
I have loaded xml documents into vb by using the Document Object Model. Once loaded, you can create a list of all elements and loop though the data in the element. You need to reference msxml 2.0.

Dim objDom As MSXML.DOMDocument
Dim DocNodelist As MSXML.IXMLDOMNodeList
Dim iPos As Integer
Set objDom = New DOMDocument
objDom.async = False 'wait for document to load before proceding with the execution of code
objDom.Load &quot;c:\file.xml&quot; 'Load document into dom
If objDom.parseError <> 0 Then 'Check for errors in document
With objDom.parseError
Debug.Print &quot; Error Code: &quot; & .errorCode ' The error code
Debug.Print &quot; File Pos: &quot; & .filepos ' The absolute file position in the XML document containing the error
Debug.Print &quot; Line No: &quot; & .Line ' The line number in the XML document where the error occured
Debug.Print &quot;Character Pos: &quot; & .linepos ' The character position in the line containing the error
Debug.Print &quot; Reason: &quot; & .reason ' The cause of the error occured
Debug.Print &quot; Text: &quot; & .srcText ' The data where the error occured
Debug.Print &quot; URL: &quot; & .url ' The url of the XML document containing the error
Exit Sub
End With
End If

Set DocNodelist = objDom.getElementsByTagName(&quot;*&quot;) 'Create a list of all nodes
Debug.Print &quot;Text in first element: &quot; & DocNodelist.Item(0).Text



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top