cancel
Showing results for 
Search instead for 
Did you mean: 

SelectSingleNode not finding XML nodes; trying to setProperty("SelectionNamespaces", ...)

SOLVED
Highlighted
Occasional Contributor

SelectSingleNode not finding XML nodes; trying to setProperty("SelectionNamespaces", ...)

I am trying to use SelectSingleNode() to find any node other than the root for this XML:  

 

<?xml version="1.0?>
<myRootNode xmlns:xsl="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="my:set:of:coloned:stuff">
  <level1Node1>
    <level2Node1>
      <level3Node1>L3N1Value</level3Node1>
    </level2Node1>
    <level2Node2>
      <level3Node1>L3N1Value</level3Node1>
    </level2Node2>
  </level1Node1>
  <level1Node2>
    <level2Node1>
      <level3Node1>L3N1Value</level3Node1>
    </level2Node1>
  </level1Node2>
</myRootNode>

 

 After properly loading the doc and assigning root=doc.documentElement, I am trying

 

L3N1 = root.SelectSingleNode("/level1Node1")

 

L3N1 returns None. The only way anything non-None returns is with "/*" or "//*" -- which return the root.

Maybe it's because the start has "xmlns" stuff in it. So now I'm trying to set a namespace using the value that I find in root.namespaceURI

 

doc.setProperty('SelectionNamespaces', 'xmlns="my:set:of:coloned:stuff"')

 

but that doesn't work either.

What is the correct incantation for this?

1 ACCEPTED SOLUTION

Accepted Solutions
Occasional Contributor

Finally figured out how the SelectionNamespaces stuff works:  

doc.setProperty("SelectionNamespaces", "xmlns:<your_abbreviation>=<your_namespace>"

which can then be used as

nodeToFind = parentNode.SelectSingleNode("<your_abbreviation>:<tag1>/<your_abbreviation>:<tag2>")

I need "<your_abbreviation>:" at all levels, because the namespace is at the root. In my case

doc.setProperty('SelectionNamespaces', 'xmlns:abbrev="my:set:of:coloned:stuff"')
L3N1 = root.SelectSingleNode("abbrev:level1Node1")

works, adding "abbrev" and dropping the leading "/"

View solution in original post

3 REPLIES 3
Highlighted
Community Leader

Did you try the already posted solution here: https://community.smartbear.com/t5/TestComplete-Desktop-Testing/reading-xml-using-selectSingleNode/t... ?

 

Un sourire et ça repart

Highlighted
Occasional Contributor

Already read that. It doesn't address the problem of the namespace.

Occasional Contributor

Finally figured out how the SelectionNamespaces stuff works:  

doc.setProperty("SelectionNamespaces", "xmlns:<your_abbreviation>=<your_namespace>"

which can then be used as

nodeToFind = parentNode.SelectSingleNode("<your_abbreviation>:<tag1>/<your_abbreviation>:<tag2>")

I need "<your_abbreviation>:" at all levels, because the namespace is at the root. In my case

doc.setProperty('SelectionNamespaces', 'xmlns:abbrev="my:set:of:coloned:stuff"')
L3N1 = root.SelectSingleNode("abbrev:level1Node1")

works, adding "abbrev" and dropping the leading "/"

View solution in original post

New Here?
Join us and watch the welcome video:
Announcements
Join TechCorner Challenge!
Want a fun and easy way to learn TestComplete? Try solving weekly TechCorner challenges and get into the Leaderboard!


Challenge Status

Get properties of a web page element

Participate!

Compare images using the Region Checkpoint

See replies!

Compare HTML table with Excel file and correct data in Excel file

Participate!

How to execute remote test and obtain results via Test Runner REST API

Participate!
Top Kudoed Authors