I want to save The whole content of XML file to a string or stringbuilder. Please let me know how can i achive that??
My Function needs to copy or Save a XML file content Completely to string or stringbuilder.
It is External Content(XML File).After that I need to change the Content(onf field ) of the xml file Can i achive it through C#. please let me know.
I Have following content in XML format , i want to put into one string and pass that to another Function in order to achive my Work.
<wsa:Address xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address>
<wsa:ReferenceParameters xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsman="http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd">
<wsman:ResourceURI>http://schema.unisys.com/wbem/wscim/1/cim- </wsa:ReferenceParameters>
</p:Source>
</p:INPUT>";
--------------------------------------------------
Regards,
Channaa
Reading an XML file into a string is simple:
string xml = File.ReadAllText(fileName);
The to access the content, you would read it into an XmlDocument:
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
using System.Xml.Linq;
// load the file
var xDocument = XDocument.Load(@"C:\MyFile.xml");
// convert the xml into string (did not get why do you want to do this)
string xml = xDocument.ToString();
Now, using xDocument, you can manipulate the XML & save it back -
xDocument.Save(@"C:\MyFile.xml");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With