How to make XMLDOMDocument include the XML Declaration?

后端 未结 5 1149
小鲜肉
小鲜肉 2021-01-12 06:29

When an XMLDOMDocument saves itself, how can i get it to include the XML Declaration, e.g.:

5条回答
  •  独厮守ぢ
    2021-01-12 07:13

    You should be able to acheive the same thing by using the CreateProcessingInstruction method.

    Example;

    ' Create and load a DOMDocument object.
    
    Dim xmlDoc As New DOMDocument
    Dim xRecords As IXMLDOMElement
    
    ' Make the Records the root node and add instructional line to XML file.
    Set xRecords = xmlDoc.createElement("HeuristicFiler")
    xmlDoc.appendChild xmlDoc.createProcessingInstruction("xml", "version=""1.0"" encoding=""UTF-8"" standalone=""yes""")
    xmlDoc.appendChild xRecords
    
    '  Add various records
    
    ' Save the XML File 
    xmlDoc.Save strFilePath
    

提交回复
热议问题