Forum Discussion
pravin_k99
Contributor
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?
AlexKaras
6 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
- 2 years agodavid-beltran
- 8 years agodivergentor
- 4 years agorajs2020
Recent Discussions
- 12 hours agoashly