473,320 Members | 1,825 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

trouble about using the function selectSingleNode

I want to handle some XML data. If the node "mywebs" doesn't have the attribution "xmlns", oXmlDomA.selectSingleNode("/mywebs/web/index") works well.But now the following code returns null to disWebA. How to realize my purpose?

Thank you.

Expand|Select|Wrap|Line Numbers
  1. var oXmlDomA = createXMLDOM();
  2. oXmlDomA.loadXML("<mywebs xmlns='http://tempuri.org/'><web><index>0</index><nextID>-1</nextID><ID>0</ID><Name>best video</Name><Link>www.youtube.com</Link><Note>the most famous video web</Note><Cate>video</Cate><Cr>99</Cr><Key>vedio,entertainment,</Key><Lans><string>English</string></Lans></web><web><index>0</index><nextID>-1</nextID><ID>1</ID><Name>search Engine</Name><Link>www.yahoo.com</Link><Note>the most famous video web</Note><Cate>video</Cate><Cr>99</Cr><Key>search,entertainment,</Key><Lans><string>English</string><string>Jepanese</string></Lans></web></mywebs>");
  3. var disWebA=oXmlDomA.selectSingleNode("/mywebs/web/index") 
I have tried adding
Expand|Select|Wrap|Line Numbers
  1. " oXmlDomA.setProperty("SelectionLanguage", "XPath");
  2.   oXmlDomA.setProperty("SelectionNamespaces","xmlns='http://tempuri.org/'");
  3. "
before

Expand|Select|Wrap|Line Numbers
  1.  var disWebA=oXmlDomA.selectSingleNode("/mywebs/web/index") 
But disWebA remains null. My browser is IE8.

Thank you so much.
Mar 9 '10 #1
3 2483
jkmyoung
2,057 Expert 2GB
Try using prefixes:
Expand|Select|Wrap|Line Numbers
  1. oXmlDomA.setProperty("SelectionNamespaces","xmlns:a= 'http://tempuri.org/'");
  2. ....
  3.  
  4. var disWebA=oXmlDomA.selectSingleNode("/a:mywebs/a:web/a:index") 
  5.  
I forget offhand why setting the default namespace might not work, sorry.
Mar 9 '10 #2
Unfortunately, it doesn't work.

there is the html page http://www.yanglihao.com/parseXMLtoJavascriptObject.htm
Mar 10 '10 #3
jkmyoung
2,057 Expert 2GB
Try selecting the root node first and make sure it isn't null. Then build on top of that.

===
In your code:
var disWeb=disWebs.selectSingleNode("/mywebs[@xmlns='http://tempuri.org/']/web/index");

This doesn't work because xmlns is not an attribute, it is a namespace node.
You want:

var disWeb=disWebs.selectSingleNode("/mywebs[namespace-uri()
='http://tempuri.org/']/web[namespace-uri()
='http://tempuri.org/'/index[namespace-uri()
='http://tempuri.org/'");

Not sure why prefixing isn't working for you.
Mar 10 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Tim:.. | last post by:
Hi Possibly a very simple question but how do I get a value out of an XML document so I can play with it in ASP E.G: <Name>Tom</Name How do I pull the work tom into asp Thanks
7
by: Jason | last post by:
Hi I have an XML file i need to load and read the contents. Here is the top part of the xml file. <Research xsi:schemaLocation="http://www.rixml.org/2002/6/RIXML...
1
by: Angela | last post by:
I am getting an error when I attempt to access a node with SelectSingleNode(): "The expression passed to this method should result in a NodeSet." I understand there is some confusion when you have...
19
by: David Thielen | last post by:
Hi; If there are no namespaces this works fine for me. But if the xml has namespaces, then I get either no node back or an exception. Here is the sample xml: <root xmlns="http://www.test.org"...
2
by: Shawn | last post by:
Hi, I'm looping through an XmlNodeList and the second XmlNode in the list contains this OuterXml: <element><name>plant</name><value>100</value></element> Next I have this XPath (inside the loop):...
2
by: yofnik | last post by:
How do you check if a function exists in IE? If I try the following: if(document.selectSingleNode) { document.selectSingleNode(xpath); } I get an error saying the wrong number of arguements...
6
by: Derek Hart | last post by:
I bring in an xml file into vb.net by using xmlDoc.LoadXml(XMLString) - I run xpath statements against the xml file to grab data from it, so I use, as an example, //Vehicles/Vehicles/@make to get...
1
by: pds79 | last post by:
Hi everyone, I'm a newbie to the forum. I have an issue and was hoping to get some assistance/ideas: Im trying to read a XML file into two record sets. I can acheive looping through the...
12
by: andyoye | last post by:
I have two date fields(startDate, endDate) in a form and I want to calculate number of days between startDate & endDate. Thanks
0
by: savage678 | last post by:
Hi Everyone, I am new to this forum and am i dire need of some help. I am trying to use wildcard searches in infopath. I have it connected to an access database using data connection. I have...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.