Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How do I write XML into XMLDocument?

How do I write XML into XMLDocument?

Scheduled Pinned Locked Moved C#
questiondatabasexmljson
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    oceanexplorer
    wrote on last edited by
    #1

    Hi, I am currently returning an XmlDocument from a webservice using the following: [OperationContract] [FaultContract(typeof(Anaqua.Domain.AnaquaServiceError))] [XmlSerializerFormat] public XmlDocument GetLawUpdateGenerationXML(short versionNum) { ///Code here to gets the xml from the db } Then in my page that consumes the webservice I did the following: XmlDocument doc = (XmlDocument)svc.GetLawUpdateGenerationXML(internalVersionNumber); However it is saying: Cannot convert type 'System.Xml.XmlElement' to 'System.Xml.XmlDocument' Now I think this is because of the serialization using[XmlSerializerFormat] So how would I go about reading the XML into and XML Document? Regards Paul Custance

    P S 2 Replies Last reply
    0
    • O oceanexplorer

      Hi, I am currently returning an XmlDocument from a webservice using the following: [OperationContract] [FaultContract(typeof(Anaqua.Domain.AnaquaServiceError))] [XmlSerializerFormat] public XmlDocument GetLawUpdateGenerationXML(short versionNum) { ///Code here to gets the xml from the db } Then in my page that consumes the webservice I did the following: XmlDocument doc = (XmlDocument)svc.GetLawUpdateGenerationXML(internalVersionNumber); However it is saying: Cannot convert type 'System.Xml.XmlElement' to 'System.Xml.XmlDocument' Now I think this is because of the serialization using[XmlSerializerFormat] So how would I go about reading the XML into and XML Document? Regards Paul Custance

      P Offline
      P Offline
      pmarfleet
      wrote on last edited by
      #2

      This link[^] should answer your question. Paul

      1 Reply Last reply
      0
      • O oceanexplorer

        Hi, I am currently returning an XmlDocument from a webservice using the following: [OperationContract] [FaultContract(typeof(Anaqua.Domain.AnaquaServiceError))] [XmlSerializerFormat] public XmlDocument GetLawUpdateGenerationXML(short versionNum) { ///Code here to gets the xml from the db } Then in my page that consumes the webservice I did the following: XmlDocument doc = (XmlDocument)svc.GetLawUpdateGenerationXML(internalVersionNumber); However it is saying: Cannot convert type 'System.Xml.XmlElement' to 'System.Xml.XmlDocument' Now I think this is because of the serialization using[XmlSerializerFormat] So how would I go about reading the XML into and XML Document? Regards Paul Custance

        S Offline
        S Offline
        Spacix One
        wrote on last edited by
        #3

        If you wish to append a child node to the document root of an already created XML file then be sure to have using System.Xml; then the following will add a node:

                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load("path to your xml file that already had a root document node");
                XmlNode newXmlNode = xmlDoc.CreateElement("tagname");
                newXmlNode.AppendChild(xmlDoc.CreateTextElement("The tag's text node Value"));
                xmlDoc.DocumentElement.AppendChild(newXmlNode);
        

        -Spacix All your skynet questions[^] belong to solved

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups