Forum Discussion
Sorry
The link seems to be broken. Would you be able to post your solution here please?
Thanks
pravin_k99 wrote:
Sorry
The link seems to be broken. Would you be able to post your solution here please?
Thanks
The link is corrected... the page referenced gives some examples in JScript code. The link TanyaYatskovska provided gives some code examples as well. I don't have the code at my fingertips... that was at a different job so not immediately available and, unfortunately, I don't have time to reinvent it...
- pravin_k996 years agoContributor
Thanks Robert and Tanya
I wrote this piece of code but unfortunately, it works only when I remove namespaces from the XML.
<BasicExport xmlns="http://www.in.casds.com/SSR/XTI/Traffic/0011" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.uk.nds.com/SSR/XTI/Traffic/0011 0011_export.xsd" transactionIdentifier="585073235185"> REPLACED with <BasicExport>
function FirstValue() { var Doc, s, Nodes, ChildNodes, i, Node; Doc = getActiveXObject("Msxml2.DOMDocument.6.0"); Doc.async = false; Doc.load("C:\\mytest.xml"); if(Doc.parseError.errorCode != 0) { s = "Reason:\t" + Doc.parseError.reason + "\n" + "Line:\t" + aqConvert.VarToStr(Doc.parseError.line) + "\n" + "Pos:\t" + aqConvert.VarToStr(Doc.parseError.linePos) + "\n" + "Source:\t" + Doc.parseError.srcText; Log.Error("Cannot parse the document.", s); return; } Nodes = Doc.selectNodes("//caProductId"); Log.Message(Nodes.item(1).childNodes.item(1).text); }
Though there is an example for namespace based XML. My XML seems to have namespace only in the first tag and then the rest of the xml doesnot use the namespace.
Can you please help?
- TanyaYatskovska6 years agoSmartBear Alumni (Retired)
Hi,
What do you mean when you say " the code doesn't work"? Do you see any errors/exceptions? Please post them here.
Also, it's worth seeing your xml file (at least the structure of the file). Could you please post it here?
- TanyaYatskovska6 years agoSmartBear Alumni (Retired)
- AlexKaras6 years agoChampion Level 3
Hi,
> it works only when I remove namespaces from the XML.
Try this:
a)
oXml = Sys.OleObject("Msxml2.DOMDocument"); oXml.async = false; oXml.setProperty("SelectionLanguage", "XPath");
and
b)
// function returns namespace-agnostic form of the searched parameter // From: http://jcooney.net/archive/2005/08/09/6517.aspx function GetNamespaceAgnosticXPathClause(strClause) { return aqString.Format(".//*[local-name()=\"%s\"]", strClause) // search recursively from the current node }
Sample usage:
strValue = "//" + GetNamespaceAgnosticXPathClause("caProductId");
Nodes = Doc.selectNodes(strValue);Does the above help?
Related Content
- 4 years agorajs2020
- 5 years agoKrishna_Kumar
Recent Discussions
- 3 days agovladd1