I have below a sample xml that I'm trying to manipulate John I will have a string that I want to append to my existing xml shown below: "Doe" My question is, instead of creating a new node using the createnode method of the xml document, I want to append the
string that I have to the xml. I noticed that there is the a "createtextnode" method, and it does what I need it to do, but when I render the xml to the browser, the format is not correct. Below is what the xml would look like John lt;LastNamegt;Doelt;/Lastnamegt;
Is there a better way to append an existing string representation of an xml Thanks,
Have you tried to use "<" and ">" symbols directly instead of using lt and gt in the createTextNode? Since it is a textnode, it should accept it and the browser should not complain. just my half cent idea. :)
I interpret the
MSDN: CreateTextNode Method documentation differently. If you look at the example code, CreateTextNode does not actually create an XmlElement, but is used to add the text to an XmlElement. So all you've done is added that text to the Person element. Unfortunately,
without spending more time on this, I don't have the answer to your specific scenario. Since you have the chunk of XML, you need a LoadXml() method similar to what XmlDocument offers. You might load the xml into an XmlDocument and then insert the appropriate
XmlNode into your existing xml object. Not quite sure if there are other classes that have a LoadXml() method that might be easier to work with. Hope that helps. Matt
I can see how this might be a little confusing to read. A text node in XML is simply the text contained in an element.
baz
There are actually 3 nodes within this document (not counting the document itself, which is also a node): The "foo" element, "bar" element,
and "baz" text node. In other words, an element does not have a value, it has a child text node. The text node actually has the value. To ensure that the XML document is well-formed, illegal characters are escaped for you. That is why you got the "<" escape
characters, because "<" is illegal as a character as the value of a text node or attribute.
tinman1412
Member
360 Points
76 Posts
Appending a Node
Jul 30, 2003 01:24 PM|LINK
HelpWanted
Participant
805 Points
161 Posts
Re: Appending a Node
Jul 31, 2003 04:31 PM|LINK
Matt Smith
Member
70 Points
14 Posts
Re: Appending a Node
Jul 31, 2003 09:38 PM|LINK
Chief Swoof at swoofware.com
kaevans
Participant
1150 Points
230 Posts
Microsoft
Re: Appending a Node
Aug 06, 2003 08:31 PM|LINK
kaevans
Participant
1150 Points
230 Posts
Microsoft
Re: Appending a Node
Aug 06, 2003 08:36 PM|LINK
XmlDocument doc = new XmlDocument(); doc.LoadXml ("baz"); XmlNode bar = doc.SelectSingleNode("/foo/bar"); bar.InnerXml = "it works!";