0% found this document useful (0 votes)
64 views2 pages

How To Get The Values of The XML Tags

This document provides code to retrieve tag values from an XML file. It loads an XML file called "sample.xml" using the Microsoft XML DOM object. It then uses the SelectNodes method and XPath queries to retrieve the text values of specific tags, like "/catalog/book/author" to get all author names. Message boxes display the number of matching nodes and their values. This allows extracting data from the XML tags without having to parse the file contents directly.

Uploaded by

vijayap71
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views2 pages

How To Get The Values of The XML Tags

This document provides code to retrieve tag values from an XML file. It loads an XML file called "sample.xml" using the Microsoft XML DOM object. It then uses the SelectNodes method and XPath queries to retrieve the text values of specific tags, like "/catalog/book/author" to get all author names. Message boxes display the number of matching nodes and their values. This allows extracting data from the XML tags without having to parse the file contents directly.

Uploaded by

vijayap71
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

XML

How to get the values of the XML tags ? => Content of "sample.xml" file from which the tag values will retrieved using below code <catalog> <book id="bk101"> <author>Gambardella, Matthew</author> <title>XML Developer's Guide</title> <genre>Computer</genre> <price>44.95</price> <publish_date>2000-10-01</publish_date> <description>An in-depth look at creating applications with XML.</description> </book> <book id="bk102"> <author>Ralls, Kim</author> <title>Midnight Rain</title> <genre>Fantasy</genre> <price>5.95</price> <publish_date>2000-12-16</publish_date> <description>A former architect battles corporate zombies, an evil sorceress, and her own childhood to become queen of the world.</description> </book> </catalog> Code 'Create Microsoft.XMLDOM object Set xmlDoc = CreateObject("Microsoft.XMLDOM") xmlDoc.Async = False 'path of XML file XMLDataFile="D:\sample.xml" 'Load the XML File xmlDoc.Load(XMLDataFile) 'Give the XML path of XML tag you want to access and /text() to access the value of tag. 'XML path follows the hierarchy 'XML path for author tag will start from catalog->book->author 'so the XML path will be /catalog/book/author 'Text() will gie the value of the tag

Set nodes = xmlDoc.SelectNodes("/catalog/book/author/text()") Msgbox " total count of Author tag is " & nodes.length For i = 0 To (nodes.Length - 1) Author= nodes(i).NodeValue Msgbox "The name of Author is " & Author Next 'To get the description tag value in the XML file Set nodes = xmlDoc.SelectNodes("/catalog/book/description/text()") Msgbox " total count of Description tag is " & nodes.length For i = 0 To (nodes.Length - 1) Descripton= nodes(i).NodeValue Msgbox "The Description is < " & Descripton & " > " Next Set xmlDoc=nothing

You might also like