Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

selectSingleNode with namespace 1

Status
Not open for further replies.

dboira

Programmer
Dec 17, 2001
10
ES
when I make an selectSingleNode refer to an xml file with namespace I obtain an error. The same xml without the namespace works ok. somebody knows something??

* With namespace (xmlDoc.selectSingleNode() doesn't work):
<?xml version="1.0" encoding="UTF-8"?>
<basededades xmlns="C:\Esquemes\Qualif" xmlns:xsi=" xsi:schemaLocation="C:\Esquemes\Qualif Versio_bbdd2.xsd">
<taules>
...
</taules>
</basededades>

* Without namespace (xmlDoc.selectSingleNode() works correctly):
<?xml version="1.0" encoding="UTF-8"?>
<basededades>
<taules>
...
</taules>
</basededades>
 
This is a common question, not an obvious solution and in my opinion a stupid idiosyncracy of XML. When you have a default namespace, to transform it you must use a namespace prefix even though it is the default in the XML doc. See this for more info:


So, to fix your problem you need to specify the selection namespace as a prefix:

xml.setProperty "SelectionNamespaces", "xmlns:myprefix='C:\Esquemes\Qualif'"

Then specify your nodes thusly:

mynode/anothernode[yetanothernode='value']

becomes

myprefix:mynode/myprefix:anothernode[myprefix:yetanothernode='value']

By the way, I don't think your namespace is valid. That won't cause a problem, but it should point to a unique URL.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top