|
Forums » .NET » XML »
|
NotSupportedException shows when tried to write to an XML file |
Posted Date: 19 Jun 2012 Posted By:: savanth Member Level: Silver Member Rank: 1557 Points: 5
Responses:
2
|
XPathDocument doc = new XPathDocument(Server.MapPath("XMLFile.xml")); XPathNavigator nav = doc.CreateNavigator();
// Compile a standard XPath expression XPathExpression expr;
//expr = nav.Compile("/Sections/Section/SubSections/SubSection/Questions/Question[@Code='" + DropDownList1.SelectedValue + "']");
//XPathNodeIterator iterator = nav.Select("/Sections/Section/SubSections/SubSection/Questions/Question[@Code='" + DropDownList1.SelectedValue + "']");
XPathNodeIterator iterator = nav.Select("/catalog/cd/price"); int a = iterator.Count; // Iterate on the node set //ListBox1.Items.Clear(); if (a > 0) { while (iterator.MoveNext()) { iterator.Current.SetValue("1234"); } }
When I tried to write data to an xml file, it shows the error "Specified method is not supported" So could anyone plz help me to solve this issue....
|
Responses
|
#676164 Author: Anil Kumar Pandey Member Level: Platinum Member Rank: 1 Date: 19/Jun/2012 Rating:  Points: 4 | It seems that the method you are using is not present for that class, make use of proper name space before making use of this code.
here is another method to create an XML file.
public void createXML() { XmlDocument doc = new XmlDocument();
string filename="c:\\sample.xml"; XmlTextWriter tw=new XmlTextWriter(filename,null);//null represents the Encoding Type// tw.Formatting=Formatting.Indented; //for xml tags to be indented// //tw.WriteStartDocument(); //Indicates the starting of document (Required)//
//tw.WriteStartElement("Employees"); //tw.WriteStartElement("Employee","Genius"); //tw.WriteAttributeString("Name","krishnan"); //tw.WriteElementString("Designation","Software Developer"); //tw.WriteElementString("FullName","krishnan Lakshmipuram Narayanan");
tw.WriteStartElement("Author"); tw.WriteElementString("ID","1"); tw.WriteElementString("SubmissionDate","1-1-08"); tw.WriteElementString("Topic","test"); tw.WriteElementString("Title","test"); tw.WriteStartElement("Authors"); tw.WriteStartElement("Author"); tw.WriteElementString("Name","XYZ"); tw.WriteElementString("Affiliation","ABC"); tw.WriteEndElement(); tw.WriteEndElement(); tw.WriteElementString("Summary","Hi"); tw.WriteElementString("Text","Hello");
tw.WriteEndElement(); //tw.WriteEndDocument(); tw.Flush(); tw.Close();
StreamReader srXml = new StreamReader(filename); string xmlFile = srXml.ReadToEnd();
}
Thanks & Regards Anil Kumar Pandey Microsoft MVP, DNS MVM
| #676212 Author: savanth Member Level: Silver Member Rank: 1557 Date: 19/Jun/2012 Rating:  Points: 1 | Thanks Anil... Anyway I find out the issue.... Itz bcoz XPathNavigator objects created by XPathDocument objects are read-only. So it should be created with XMLDocument to be editable.
|
|
| Post Reply |
|
|
|
 | | This thread is locked for new responses. Please post your comments and questions as a separate thread. If required, refer to the URL of this page in your new post. |
|
|
|
|
 Follow us on Twitter: https://twitter.com/dotnetspider
|
|