1
<feed>
    <entry>
        <data>1234</data>
        <content>Stackoverflow</content>
    </entry>
</feed>
Next data..

I have to create above xml using xpath in c# is this possible to do..

I had done xml file using below code

                    XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load(@"C:\Log_Data.xml");

        XmlElement newelement = xmlDoc.CreateElement("entry");
        XmlElement xmldata = xmlDoc.CreateElement("data");
                    XmlElement xmlcontent = xmlDoc.CreateElement("content");

                    xmldata.InnerText ="1234" ;
        xmlcontent.InnerText ="Stackoverflow";

                    newelement.AppendChild(xmldata);
        newelement.AppendChild(xmlcontent);

                    xmlDoc.DocumentElement.AppendChild(newelement);
        xmlDoc.Save(@"C:\Log_Data.xml");

but i have to use Xpath like we do in sql to write queries like "Insert into table............." should it possible in .Net 2.0

Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431
lax
  • 518
  • 2
  • 11
  • 26

2 Answers2

2

XPath is a query language for XML documents. As such, it doesn't provide the capability to alter (delete or insert nodes) an XML document.

One of the most appropriate ways to create or alter an XML document (called XML transformation) is to use XSLT -- a language especially designed for XML transformations.

From C# one can use the .NET XslCompiledTransform class to perform any XSLT 1.0 transformation.

Third party .NET implementations exist for XSLT 2.0.

Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431
0

You have to create your own XPath parser to achieve this. Simple implementation of that can be found here.

Community
  • 1
  • 1
Rohit Vats
  • 79,502
  • 12
  • 161
  • 185
  • if i create xpath then it should remove concurrency means at a time two process write the file then i have to avoid process exception – lax Oct 14 '12 at 11:47
  • Have you tried this - http://stackoverflow.com/questions/508390/create-xml-nodes-based-on-xpath – Rohit Vats Oct 14 '12 at 12:19