Xml Declaration in C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • babai28
    New Member
    • Jul 2008
    • 59

    Xml Declaration in C#

    Hi All,

    I have a situation in which I need to write the XML Declaration of an XmlDocument (that I am creating) from a hard coded text.
    How to acieve this? I have tried with the inner text property of XmlDeclaration node etc. but it is throwing errors. Please guide.
    I am using C#, however if you can show me the VB way I can very well appreciate that.
    Thanks for reading my problem.

    Regards,
    Sid
  • nukefusion
    Recognized Expert New Member
    • Mar 2008
    • 221

    #2
    Hi babai28,

    It's difficult to see exactly what is going wrong without an example of what you are currently trying, however, you could use something like the following in order to write the Declaration in an XmlDocument object:

    Code:
    xmlDoc = new XmlDocument();
    xmlNode=xmlDoc.CreateNode(XmlNodeType.XmlDeclaration,"","");
    xmlDoc.AppendChild(xmlNode);
    The empty strings are spaces for the name and namespace URI.

    Comment

    Working...