dotnetspider.com
Login Login    Register      

TutorialsForumCareer DevelopmentResourcesReviewsJobsInterviewCommunitiesProjectsTraining

Subscribe to Subscribers
Talk to Webmaster
Tony John

Facebook
Google+
Twitter
LinkedIn
Online Membersnaveensanagasetti
premkumar
Chandra
Padma
Shine S
Asheej T K
Kavery
baiju
More...
Join our online Google+ community for Bloggers, Content Writers and Webmasters




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: 2 out of 52 out of 5     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: 2 out of 52 out of 5     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.



Next : Xml document to tree structure
Previous : How to parse the xml
Return to Discussion Forum
Post New Message
Category:

Related Messages



Follow us on Twitter: https://twitter.com/dotnetspider

Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds


    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.