Hi,
I would like to add an XmlElement that looks like this:
<data:lvalue-possibles>
Here is my current code.
This code is part of a function which returns an XMLNode. It also overrides a function of another class. It takes the XMLNode returned by that baseclass function and just adds the new tag.Code:XmlDocument root = new XmlDocument(); XmlNode attr = root.ImportNode(base.Xml,true); root.AppendChild(attr); XmlElement possibles = root.CreateElement("data:lvalue-possibles"); possibles.Prefix = "data"; attr.AppendChild(possibles); return attr;//returns the XmlNode
Here's some explanations of the code above:
1) To create an XmlElement there is always an XmlDocument needed. So first I create the XmlDocument.2) As I said earlier the function overrides another function. First we'll need to convert the tags of the basefunction to the newly created document.Code:XmlDocument root = new XmlDocument();3) Here we make those tags the root of our document.Code:XmlNode attr = root.ImportNode(base.Xml,true);4) Next we create the new XMLElement.Code:root.AppendChild(attr);5) I am trying really hard to set the prefix to "data:...".Code:XmlElement possibles = root.CreateElement("data:lvalue-possibles");6) After that the new element is added to the previous one.Code:possibles.Prefix = "data";I have no idea why, but this does not work. Everything works fine that is, except the prefix. No matter what I try the prefix does not show up. The output is this:Code:attr.AppendChild(possibles);
When I debug I can see that even right after the 4th step there is no prefix in the InnerXML property. So it looks like it was never added.<baseclasstags>
<lvalue-possibles />
</baseclasstags>
Does anybody know how I can set the prefix anyway?


Reply With Quote
seems like it did indeed work like that !
