Pages

Monday, December 8, 2014

Working with XML

Accessing XML

Dim StrXmldatafile=c:\test.xml

Set xmldoc=createobject("Microsoft.XMLDOM"")
Xmldoc.async=false

Xmldoc.load(StrXmldatafile)

'get number of nodes
Set nodes=Xmldoc.selectnodes("/bookstore/book")
Msgbox "total books" &nodes.length

'get title of all books
Set nodes=Xmldoc.selectnodes("/bookstore/book/title/text()")
'get their value
For I=0 to ( nodes. Length -1)
Title = nodes(I).nodevalue
Msgbox " title#"&(I+1)&":"&title
Next

'get first book element that is child of bookstore element
Setnodes=xmldoc.selectnodes("/bookstore/book[1]")

'get last book element that is child of bookstore element
Strnodes=xmldoc.selectnodes("/bookstore/book[last()]")

'get all title element that have attribute name Lang
Strnodes=xmldoc.selectnodes("//title[@Lang]")

'get all title element that have attribute name Lang with value English
Strnodes=xmldoc.selectnodes("//title[@Lang='english']")

'get all book element of bookstore element that have price element with value >35
Strnodes=xmldoc.selectnodes("/bookstore/book[price>35.]")

'get all title element of book element of bookstore element that have price element with value > 35
Strnodes=xmldoc.selectnodes("/bookstore/book[price>35.00]/title")

4 comments:

  1. Thank you for this post. Thats all I are able to say. You most absolutely have built this blog website into something speciel. You clearly know what you are working on, youve insured so many corners.thanks
    Python training in marathahalli | Python training institute in pune

    ReplyDelete
  2. Just stumbled across your blog and was instantly amazed with all the useful information that is on it. Great post, just what i was looking for and i am looking forward to reading your other posts soon!

    Data Science training in Chennai | Data science training in bangalore

    Data science training in pune | Data science online training

    Data Science Interview questions and answers

    ReplyDelete