1. Vipin Dwivedi
  2. PowerBuilder
  3. Tuesday, 31 July 2018 18:40 PM UTC

Hi,

Our application has been using Msxml2.DomDocument.3.0 in our application and working fine to traversing node in XML.

Recently we upgraded our code and started using Msxml2.DomDocument.6.0 version but this is failing to use SelectNodes for the same XML which is working fine with 3.0. This is failing only if Node is having a colon (:). See below XML content




Below is code

OLEObject aole_object,objNodeList
CONSTANT STRING XPATH_GENERALSTATUS = '//ns2:retrieveAgreementResponse/generalStatus'
aole_object = CREATE OLEObject
li_oleConnectionStatus = aole_object.ConnectToNewObject ('Msxml2.DOMDocument.6.0')
aole_object.async = FALSE
ls_XML = of_get_xml_from_file(as_FileName) //This function returns xml content into String variable.
aole_object.LoadXML (ls_XML)
objNodeList = aole_dom.DocumentElement.SelectNodes(XPATH_GENERALSTATUS); //This is failing in version 6.0 but working fine with version 3.0

Please help and guide me.

Thanks,

Vipin

 

Ken Guo @Appeon Accepted Answer Pending Moderation
  1. Wednesday, 1 August 2018 10:17 AM UTC
  2. PowerBuilder
  3. # 1

Hi Vipin,

René is right, but please add this PB code to set the XML namespace:

aole_dom.setProperty ("SelectionNamespaces", 'xmlns:ns2="http://response.dms.svap.deere.com/"')

 

BTW,

for C#, it also need set the namespace with below way:

 

XmlNodeList nodeList;
doc.LoadXml(XmlString);
XmlNode root = doc.DocumentElement;
XmlNamespaceManager nsp = new XmlNamespaceManager(doc.NameTable);
nsp.AddNamespace("ns2", "http://response.dms.svap.deere.com/");
nodeList = root.SelectNodes("//ns2:retrieveAgreementResponse/sss", nsp);

 

Regards,

Ken

 

 

Comment
There are no comments made yet.
René Ullrich Accepted Answer Pending Moderation
  1. Wednesday, 1 August 2018 05:21 AM UTC
  2. PowerBuilder
  3. # 2

I don't know the differences between the version of MSXML.

We also use version 6 to parse XML that uses namespaces.

You have to specify the namespace(s) if you want to find nodes:

aole_dom.setProperty ("SelectionNamespaces", "xmls:ns2=''http://response.dms.svap.deere.com/")

Comment
  1. Vipin Dwivedi
  2. Wednesday, 1 August 2018 13:43 PM UTC
I don't know why version 6 is looking for namespaces. If you run the same code with version 3.0, it works beautifully. I tried to looked into "whats new in version 6" under Microsoft documents but did not find any statement where it is mentioned to set namespace property before you traverse the node. This problem is coming only with colon node (ns2:). If I change the colon(:) to underscore(_) or something else, it works fine with version 6.0.

I don't want to put static value under namespace property. So what is the way to get Namespaceprefix and URL. I can use the code aloe_dom.DocumentElement.NamespaceURI to get the URL of the namespace but what about getting the prefix "xmls:ns2"?



Please help.
  1. Helpful
  1. René Ullrich
  2. Wednesday, 1 August 2018 14:08 PM UTC
I'm not a XML expert. Maybe you can define the prefix ("ns2") for your select as you want as far you use the same for "SelectionNamespaces" and in SelectNodes. If I'm right you don't need to know the prefix used in XML but you can define you own for you XPath query.
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.