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?
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?
"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
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.
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>
sorry, seems something wrong with my computer. selectNodes, selectSingleNode both work on other computer.
"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