471,350 Members | 1,803 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Problem in Xml

Hi,

I am using the following code, and the xml being generated is shown
below:

XmlNode root = document.DocumentElement;
XmlElement element = document.CreateElement("rdf", "Stadium",
RDF_PATH);
element.SetAttribute("about", null, STADIUM_PATH+"/"+stadium.Name);
root.AppendChild(element);
<rdf:Stadium about="http://www.test.fake/stadium/test" />
Now, what I require is to generate the following xml:
<rdf:Stadium rdf:about="http://www.test.fake/stadium/test" />
How can this be done.
Can someone help me out.
Thanks in Advance

Dec 24 '05 #1
3 1197
Curious <th****@mail.global.net.mt> wrote:
Hi,

I am using the following code, and the xml being generated is shown
below:

XmlNode root = document.DocumentElement;
XmlElement element = document.CreateElement("rdf", "Stadium",
RDF_PATH);
element.SetAttribute("about", null, STADIUM_PATH+"/"+stadium.Name);
root.AppendChild(element);

<rdf:Stadium about="http://www.test.fake/stadium/test" />

Now, what I require is to generate the following xml:
<rdf:Stadium rdf:about="http://www.test.fake/stadium/test" />


In that case, make the second argument to SetAttribute RDF_PATH instead
of null. I believe that should do it...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 24 '05 #2
That solved my problem.

Now I am encoutering another problem.

I have the following xml file, and I require to retrieve all the values
for the <stadium:name> tag.

I have done this earlier, but with no namespaces. The code I was using
was the following:

StreamReader reader = new StreamReader(fileName, Encoding.ASCII);
XPathDocument doc = new XPathDocument(reader);
XPathNavigator nav = doc.CreateNavigator();
XPathExpression xpe = nav.Compile("RDF/Description/name");
XPathNodeIterator xpni = nav.Select(xpe);

while(xpni.MoveNext())
{
.....
}

How can this be applied having namespaces.
Thanks in Advance

<?xml version="1.0" encoding="us-ascii" standalone="no"?>
<rdf:RDF xmlns:player="http://www.soccermanager.fake/player#"
xmlns:club="http://www.soccermanager.fake/club#"
xmlns:stadium="http://www.soccermanager.fake/stadium#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description
rdf:about="http://www.soccermanager.fake/stadium/Giuseppe Meazza di San
Siro">
<stadium:underSoilSeating>True</stadium:underSoilSeating>
<stadium:capacity>85440</stadium:capacity>
<stadium:location>Milan</stadium:location>
<stadium:covered>False</stadium:covered>
<stadium:seated>85000</stadium:seated>
<stadium:name>Giuseppe Meazza di San Siro</stadium:name>
</rdf:Description>
<rdf:Description
rdf:about="http://www.soccermanager.fake/stadium/Delle Alpi">
<stadium:underSoilSeating>True</stadium:underSoilSeating>
<stadium:capacity>81000</stadium:capacity>
<stadium:location>Torino</stadium:location>
<stadium:covered>False</stadium:covered>
<stadium:seated>79000</stadium:seated>
<stadium:name>Delle Alpi</stadium:name>
</rdf:Description>
</rdf:RDF>

Dec 24 '05 #3
Curious,

What you need to do is pass an implementation of IXmlNamespaceResolver
to the overload of the Select method. This implementation would have
namespaces associated with the tags associated with them.

Generally, to do this, you would create an instance of
XmlNamespaceManager and then pass that in with the call to Select.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Curious" <th****@mail.global.net.mt> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
That solved my problem.

Now I am encoutering another problem.

I have the following xml file, and I require to retrieve all the values
for the <stadium:name> tag.

I have done this earlier, but with no namespaces. The code I was using
was the following:

StreamReader reader = new StreamReader(fileName, Encoding.ASCII);
XPathDocument doc = new XPathDocument(reader);
XPathNavigator nav = doc.CreateNavigator();
XPathExpression xpe = nav.Compile("RDF/Description/name");
XPathNodeIterator xpni = nav.Select(xpe);

while(xpni.MoveNext())
{
....
}

How can this be applied having namespaces.
Thanks in Advance

<?xml version="1.0" encoding="us-ascii" standalone="no"?>
<rdf:RDF xmlns:player="http://www.soccermanager.fake/player#"
xmlns:club="http://www.soccermanager.fake/club#"
xmlns:stadium="http://www.soccermanager.fake/stadium#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description
rdf:about="http://www.soccermanager.fake/stadium/Giuseppe Meazza di San
Siro">
<stadium:underSoilSeating>True</stadium:underSoilSeating>
<stadium:capacity>85440</stadium:capacity>
<stadium:location>Milan</stadium:location>
<stadium:covered>False</stadium:covered>
<stadium:seated>85000</stadium:seated>
<stadium:name>Giuseppe Meazza di San Siro</stadium:name>
</rdf:Description>
<rdf:Description
rdf:about="http://www.soccermanager.fake/stadium/Delle Alpi">
<stadium:underSoilSeating>True</stadium:underSoilSeating>
<stadium:capacity>81000</stadium:capacity>
<stadium:location>Torino</stadium:location>
<stadium:covered>False</stadium:covered>
<stadium:seated>79000</stadium:seated>
<stadium:name>Delle Alpi</stadium:name>
</rdf:Description>
</rdf:RDF>

Dec 24 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Kostatus | last post: by
117 posts views Thread by Peter Olcott | last post: by
18 posts views Thread by Ian Stanley | last post: by
28 posts views Thread by Jon Davis | last post: by
6 posts views Thread by Ammar | last post: by
2 posts views Thread by Mike Collins | last post: by

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.