still wonder about NameSpace !!!

C

C# newbie

Hi guys,

Something werid happening to me. When I run a query against every xml I
have, below query works fine and returns what it should be returned.

but there is another xml file as below, which doesnt' return what it should!

I run a query like: //*[contains(.,'the string I'm looking for within the
xml goes here')]

runs fine on this: //*[contains(.,'Dylan')]

xml version="1.0" encoding="ISO-8859-1"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>

</catalog>

***************************

runs wrong on:

when I run this //*[contains(.,'center')] it doesn't find center which is
between <Header> and </Header>

<Form FormName="test" FormID="124"
StyleUsage="URL" xmlns="http://www.testdomain.com"
SurveyProgrammer="newbie" DateTime="1/30/2004 6:57:28 PM">
<Params><BackgroundColor>#19384A</BackgroundColor><LinkColor>#ffffff</LinkCo
lor><VisitedLinkColor>#ffffff</VisitedLinkColor>
<TextColor>#ffffff</TextColor><Direction>ltr</Direction><BackgroundImage></B
ackgroundImage>
<Header>&lt;table width='600' cellspacing='0' callpadding='0' border='0'
align='center'&gt;
&lt;tr&gt;&lt;td&gt;&lt;img src='images/ifilmtest.gif' alt='test'
width='175'
height='62'&gt; &lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;br&gt;&lt;br&gt;
</Header>
....
....
....
</Form>


Is the problem with NameSpace thing within the xml?




any idea?

Thanks in advance
c# newbie
 
T

Teemu Keiski

Hi,

yes it is. You need to have a prefix that matches the namespace of the
element(s) you query and you need to use that prefix in the query.

Do you use XmlDocument for querying? In that case have a look at
XmlNamespaceManager class (and the overload of XmlDocument's SelectNodes
method which takes an instance of XmlNamespaceManager). Using
XmlNamespaceManager you can specify the namespaces and their prefixes so
that they are known when XPath query is run.

If you use something else like XSLT etc, tell us more (and next time ask
this at XML newsgroup)

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist

C# newbie said:
Hi guys,

Something werid happening to me. When I run a query against every xml I
have, below query works fine and returns what it should be returned.

but there is another xml file as below, which doesnt' return what it should!

I run a query like: //*[contains(.,'the string I'm looking for within the
xml goes here')]

runs fine on this: //*[contains(.,'Dylan')]

xml version="1.0" encoding="ISO-8859-1"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>

</catalog>

***************************

runs wrong on:

when I run this //*[contains(.,'center')] it doesn't find center which is
between <Header> and </Header>

<Form FormName="test" FormID="124"
StyleUsage="URL" xmlns="http://www.testdomain.com"
SurveyProgrammer="newbie" DateTime="1/30/2004 6:57:28 PM">
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top