XML DOM select single node advice?
this is the piece of my code logic
Set targetXmlDom =CreateObject("Msxml2.DOMDocument.6.0")
targetXmlDom.setProperty "SelectionLanguage", "XPath"
LoadValue = targetXmlDom.load("C:\Users\561320\Documents\XMLCO MPARE\ACC\PRE_FIN_20131117_2243_BE0C_1.xml")
If LoadValue=True Then
Set tarObjNode = targetXmlDom.SelectsingleNode("/ReportingDocumentCollection/ReportingDocument")
MsgBox tarObjNode.selectSingleNode("/ReportingDocument/ReporterID").text 'not working
MsgBox tarObjNode.selectSingleNode("/ReportingDocument/ReporterID").text 'Working
Please forgive my coding standards .... this is logic
Why im not able to select the select single node
Any help in understanding this
what is the question?
SelectsingleNode used to find a node that contain a text node, works well in my side.
how abt using xmlUtil object.
Set XMLObj = XMLUtil.CreateXMLFromFile("\\UBSPROD.MSAD.UBS.NET\ UserData\gampav\RF\Desktop\test.xml")
set oTitle = XMLObj.ChildElementsByPath("/catalog/book/title")
Set XMLObj = Nothing
Sample Xml taken:
<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>
Is there any special case in your end that each node doesnt contain equal number of attributes or any such special cases where you will not be able to use the above approach.
Post Thanks / Like - 1 Thanks, 0 Likes, 0 Dislikes
im not using XML util because im writing in a vbs file so that i can use in the system where qtp is not installed ... The thing im doing is different from the way you posted
my question after selectingsinglenode from an xmldom ,it will return a node a object .node object will contain an xml .and then i want to use select single node in that object node .it is not working .the same if get the xml of the node object and load it to the new xml dom and then do the select single node it is working .
for example from the code snippet of the vijay .Let us take it has more catalog nodes in an XML
set node =XMLDOM.SelectSingleNode("/Catalog") 'will return 3rd node of the catalog
author =node.selectSingleNode(''/book/author'').text 'it is not working
cool..clear on your question now!!
will check and try to let you know but looks like, what you have posted should work!
set node =XMLDOM.SelectSingleNode("/catalog/book") 'cause catalog has only one book
msgbox node.selectSingleNode("./author").text 'no problem in vbs file.
Originally Posted by saikri
Sorry i dont know one concept here what is the meaning of "." here("./author") ? Is the "." was problem in the code which i earlier sent i will try with the "."
If your xpath begins with "/" then you're saying "starting from the root node of the xml." If your xpath starts with "./" then you're saying "starting with the current node." Since you assigned the current node to a different object, it should BE the root node for any xpath query you run against that object. Therefore, either syntax should work, unless the single node object you created actually stores the full xml as it's source. I don't think that's how it is supposed to work.