Jump to content

Creating XML declaration


Recommended Posts

I have one program that keep it's settings in the XML file. This is semi-valid file, because it's absent declaration, though file contain symbols that prevent MSXML parser to parse it. So for correct parsing I need to apply declaration with needed encoding to the loaded file.

Only examples I googled was NET examples. NET allow create declaration with the CreateXmlDeclaration and apply it to loaded document. How to make this in usual way?

Of course, I can merge declaration string with file content and write it to new file, but maybe exists right way to do it?

Link to comment
Share on other sites

Thanks, exactly!

Anyway, loading with Load method not works, so I used LoadXML instead - seems it's load any well formated data. Below is code for those who interested:

$oXml = ObjCreate("Msxml2.DOMdocument.3.0")
$oXml.LoadXML(FileRead("servercfg.xml", FileGetSize("servercfg.xml")))
$oXmlRoot = $oXml.documentElement
$oXmlDecl = $oXml.createProcessingInstruction("xml", 'version="1.0" encoding="UTF-8"')
$oXml.InsertBefore($oXmlDecl, $oXmlRoot)
$oXml.Save("servercfg_new.xml")
Link to comment
Share on other sites

  • 2 weeks later...

I'm curious then with the example, I know nothing about using whatever you did to lood the msxml, but if you wanted to parse an xml file and use it for a config file instead of say an ini file what commands would you use to iterate through the fields and get the data out of an xml file?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...