Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
XML
data.xmlanalysis
mappoint.webservice
msf
msxml-webrelease
netmyservices.sdk
passport.sdk
soap
soapsdk
uddi.general
uddi.programming
uddi.specification
xml
xmlsqlwebrelease
xsl
  
 
date: Sun, 15 Jun 2008 10:01:11 -0700 (PDT),    group: microsoft.public.xml        back       


why selectNodes returns nothing?   
my xml file is like this:

<?xml version="1.0" encoding="gb2312"?>
<VisualStudioPropertySheet ProjectType="Visual C++" ...>
   <UserMacro Name="test" Value="test"/>
</VisualStudioPropertySheet>


xmlmodel.selectNodes("//UserMacro");
xmlmodel.selectSingleNode("//UserMacro[@Name=test]");

both return nothing, why?
date: Sun, 15 Jun 2008 10:01:11 -0700 (PDT)   author:   thinktwice

Re: why selectNodes returns nothing?   
As for the second one, I believe it's because test is not in single quotes 
as in:

xmlmodel.selectSingleNode("//UserMacro[@Name='test']");

For the first one, have you tried:

xmlmodel.getElementsByTagName("//UserMacro");

-Scott

"thinktwice"  wrote in message 
news:378c3cab-b763-446c-bca0-01ac89a97e40@u12g2000prd.googlegroups.com...
> my xml file is like this:
>
> <?xml version="1.0" encoding="gb2312"?>
> <VisualStudioPropertySheet ProjectType="Visual C++" ...>
>   <UserMacro Name="test" Value="test"/>
> </VisualStudioPropertySheet>
>
>
> xmlmodel.selectNodes("//UserMacro");
> xmlmodel.selectSingleNode("//UserMacro[@Name=test]");
>
> both return nothing, why?
date: Sun, 15 Jun 2008 15:50:10 -0400   author:   Scott M. am

Re: why selectNodes returns nothing?   
"thinktwice"  wrote in message
news:378c3cab-b763-446c-bca0-01ac89a97e40@u12g2000prd.googlegroups.com...
> my xml file is like this:
>
> <?xml version="1.0" encoding="gb2312"?>
> <VisualStudioPropertySheet ProjectType="Visual C++" ...>
>    <UserMacro Name="test" Value="test"/>
> </VisualStudioPropertySheet>
>
>
> xmlmodel.selectNodes("//UserMacro");
> xmlmodel.selectSingleNode("//UserMacro[@Name=test]");
>
> both return nothing, why?


My guess is that the ... in your XML where you helpfully removed other
attributes hides an xmlns attribute.

You haven't specified what tech you are using but I'll guess MSXML.  In
which case you will need add the namespace indicated in the attribute to the
SelectionNamespaces for XPath.

xmlmodel.setProperty("SelectionNamespaces", "xmlns:a='name.space'")

xmlmodel.selectNodes("//a:UserMacro");
xmlmodel.selectSingleNode("//a:UserMacro[@name='test']");




-- 
Anthony Jones - MVP ASP/ASP.NET
date: Sun, 15 Jun 2008 21:52:11 +0100   author:   Anthony Jones

Re: why selectNodes returns nothing?   
thanks guys.

i have tried getElementsByTagName, it didn't work either.

i dont' quite understand this statement, but i have tried
xmlmodel.setProperty("SelectionNamespaces", "xmlns:a='name.space'") ;
xmlmodel.selectNodes("a:UserMacro");
didn't work either.
date: Sun, 15 Jun 2008 18:47:54 -0700 (PDT)   author:   thinktwice

Re: why selectNodes returns nothing?   
On 6ÔÂ16ÈÕ, ÉÏÎç9ʱ47·Ö, thinktwice  wrote:
> thanks guys.
>
> i have tried getElementsByTagName, it didn't work either.
>
> i dont' quite understand this statement, but i have tried
> xmlmodel.setProperty("SelectionNamespaces", "xmlns:a='name.space'") ;
> xmlmodel.selectNodes("a:UserMacro");
> didn't work either.

xmlmodel.xml  return :

"<?xml version=\"1.0\"?>
<VisualStudioPropertySheet ProjectType=\"Visual C\" Version=\"8.00\"
Name=\"Output\">
	<UserMacro Name=\"MyOutputRootDir\" Value=\"C:\Work\Output\\"/>
</VisualStudioPropertySheet>
date: Sun, 15 Jun 2008 18:49:31 -0700 (PDT)   author:   thinktwice

Re: why selectNodes returns nothing?   
sorry, seems something wrong with my computer.
selectNodes, selectSingleNode both work on other computer.
date: Sun, 15 Jun 2008 19:12:40 -0700 (PDT)   author:   thinktwice

Re: why selectNodes returns nothing?   
"thinktwice"  wrote in message 
news:40f0c2f2-4f03-405f-9009-5e7451972c27@j1g2000prb.googlegroups.com...
> thanks guys.
>
> i have tried getElementsByTagName, it didn't work either.
>
> i dont' quite understand this statement, but i have tried
> xmlmodel.setProperty("SelectionNamespaces", "xmlns:a='name.space'") ;
> xmlmodel.selectNodes("a:UserMacro");
> didn't work either.
I doubt if the namespace uri is 'name.space', look in the file or post the 
first element in its entirety.

-- 

Joe Fawcett (MVP - XML)

http://joe.fawcett.name
date: Mon, 16 Jun 2008 09:10:35 +0100   author:   Joe Fawcett am

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us