Results 1 to 4 of 4

Thread: setting an XmlElement its prefix.

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member BramVandenbon's Avatar
    Join Date
    Jan 2002
    Location
    Belgium
    Posts
    502

    setting an XmlElement its prefix.

    Hi,

    I would like to add an XmlElement that looks like this:
    <data:lvalue-possibles>

    Here is my current code.
    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
    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.

    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.
    Code:
    XmlDocument root = new 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:
    XmlNode attr = root.ImportNode(base.Xml,true);
    3) Here we make those tags the root of our document.
    Code:
    root.AppendChild(attr);
    4) Next we create the new XMLElement.
    Code:
    XmlElement possibles = root.CreateElement("data:lvalue-possibles");
    5) I am trying really hard to set the prefix to "data:...".
    Code:
    possibles.Prefix = "data";
    6) After that the new element is added to the previous one.
    Code:
    attr.AppendChild(possibles);
    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:
    <baseclasstags>
    <lvalue-possibles />
    </baseclasstags>
    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.

    Does anybody know how I can set the prefix anyway?
    Last edited by BramVandenbon; Sep 30th, 2006 at 03:11 PM.
    ____________________________________________

    Please rate my messages. Thank you!
    ____________________________________________
    Bram Vandenbon
    http://www.bramvandenbon.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width