0

For example, my string is:

<Here>
<Hey>smth</Hey>
<Hi>else</Hi>
</Here>

I want my document x.xml to have that content. I tried

xmlDoc.InnerXml = thatString;

but it throws an exception.

2
  • What XML document are you trying to produce? If it's not valid XML, you can't use XML code (duh!). Commented Nov 24, 2011 at 16:27
  • 3
    What exception do you get? Commented Nov 24, 2011 at 16:27

3 Answers 3

2

Try,

XElement here = XElement.Parse("<Here><Hey>smth</Hey><Hi>else</Hi></Here>");

Then to save it to a file.

here.Save("filePath");
Sign up to request clarification or add additional context in comments.

Comments

1

XmlDocument.LoadXml

http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.loadxml.aspx

even better - use linq to xml. i prefer the XDocument class of XmlDocument

Comments

0

I beleive your code is for reading only. You have to use XmlTextWriter instead.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.