Problem in Xml

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Curious

    Problem in Xml

    Hi,

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

    XmlNode root = document.Docume ntElement;
    XmlElement element = document.Create Element("rdf", "Stadium",
    RDF_PATH);
    element.SetAttr ibute("about", null, STADIUM_PATH+"/"+stadium.Name) ;
    root.AppendChil d(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

  • Jon Skeet [C# MVP]

    #2
    Re: Problem in Xml

    Curious <theone@mail.gl obal.net.mt> wrote:[color=blue]
    > Hi,
    >
    > I am using the following code, and the xml being generated is shown
    > below:
    >
    > XmlNode root = document.Docume ntElement;
    > XmlElement element = document.Create Element("rdf", "Stadium",
    > RDF_PATH);
    > element.SetAttr ibute("about", null, STADIUM_PATH+"/"+stadium.Name) ;
    > root.AppendChil d(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" />[/color]

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

    --
    Jon Skeet - <skeet@pobox.co m>
    http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
    If replying to the group, please do not mail me too

    Comment

    • Curious

      #3
      Re: Problem in Xml

      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(fi leName, Encoding.ASCII) ;
      XPathDocument doc = new XPathDocument(r eader);
      XPathNavigator nav = doc.CreateNavig ator();
      XPathExpression xpe = nav.Compile("RD F/Description/name");
      XPathNodeIterat or xpni = nav.Select(xpe) ;

      while(xpni.Move Next())
      {
      .....
      }

      How can this be applied having namespaces.
      Thanks in Advance

      <?xml version="1.0" encoding="us-ascii" standalone="no" ?>
      <rdf:RDF xmlns:player="h ttp://www.soccermanag er.fake/player#"
      xmlns:club="htt p://www.soccermanag er.fake/club#"
      xmlns:stadium=" http://www.soccermanag er.fake/stadium#"
      xmlns:rdf="http ://www.w3.org/1999/02/22-rdf-syntax-ns#">
      <rdf:Descriptio n
      rdf:about="http ://www.soccermanag er.fake/stadium/Giuseppe Meazza di San
      Siro">
      <stadium:underS oilSeating>True </stadium:underSo ilSeating>
      <stadium:capaci ty>85440</stadium:capacit y>
      <stadium:locati on>Milan</stadium:locatio n>
      <stadium:covere d>False</stadium:covered >
      <stadium:seated >85000</stadium:seated>
      <stadium:name>G iuseppe Meazza di San Siro</stadium:name>
      </rdf:Description >
      <rdf:Descriptio n
      rdf:about="http ://www.soccermanag er.fake/stadium/Delle Alpi">
      <stadium:underS oilSeating>True </stadium:underSo ilSeating>
      <stadium:capaci ty>81000</stadium:capacit y>
      <stadium:locati on>Torino</stadium:locatio n>
      <stadium:covere d>False</stadium:covered >
      <stadium:seated >79000</stadium:seated>
      <stadium:name>D elle Alpi</stadium:name>
      </rdf:Description >
      </rdf:RDF>

      Comment

      • Nicholas Paldino [.NET/C# MVP]

        #4
        Re: Problem in Xml

        Curious,

        What you need to do is pass an implementation of IXmlNamespaceRe solver
        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
        XmlNamespaceMan ager and then pass that in with the call to Select.

        Hope this helps.


        --
        - Nicholas Paldino [.NET/C# MVP]
        - mvp@spam.guard. caspershouse.co m

        "Curious" <theone@mail.gl obal.net.mt> wrote in message
        news:1135434157 .850504.153620@ g44g2000cwa.goo glegroups.com.. .[color=blue]
        > 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(fi leName, Encoding.ASCII) ;
        > XPathDocument doc = new XPathDocument(r eader);
        > XPathNavigator nav = doc.CreateNavig ator();
        > XPathExpression xpe = nav.Compile("RD F/Description/name");
        > XPathNodeIterat or xpni = nav.Select(xpe) ;
        >
        > while(xpni.Move Next())
        > {
        > ....
        > }
        >
        > How can this be applied having namespaces.
        > Thanks in Advance
        >
        > <?xml version="1.0" encoding="us-ascii" standalone="no" ?>
        > <rdf:RDF xmlns:player="h ttp://www.soccermanag er.fake/player#"
        > xmlns:club="htt p://www.soccermanag er.fake/club#"
        > xmlns:stadium=" http://www.soccermanag er.fake/stadium#"
        > xmlns:rdf="http ://www.w3.org/1999/02/22-rdf-syntax-ns#">
        > <rdf:Descriptio n
        > rdf:about="http ://www.soccermanag er.fake/stadium/Giuseppe Meazza di San
        > Siro">
        > <stadium:underS oilSeating>True </stadium:underSo ilSeating>
        > <stadium:capaci ty>85440</stadium:capacit y>
        > <stadium:locati on>Milan</stadium:locatio n>
        > <stadium:covere d>False</stadium:covered >
        > <stadium:seated >85000</stadium:seated>
        > <stadium:name>G iuseppe Meazza di San Siro</stadium:name>
        > </rdf:Description >
        > <rdf:Descriptio n
        > rdf:about="http ://www.soccermanag er.fake/stadium/Delle Alpi">
        > <stadium:underS oilSeating>True </stadium:underSo ilSeating>
        > <stadium:capaci ty>81000</stadium:capacit y>
        > <stadium:locati on>Torino</stadium:locatio n>
        > <stadium:covere d>False</stadium:covered >
        > <stadium:seated >79000</stadium:seated>
        > <stadium:name>D elle Alpi</stadium:name>
        > </rdf:Description >
        > </rdf:RDF>
        >[/color]


        Comment

        Working...