Q: issue with XML (specific DTD) edit with powershell I am dealing with a bunch of VOD meta data files (XML). There is an ADI.DTD that defines the schema of my xml.
I am trying to use powershell to edit this xml and update/change a tag using the following piece of powershell code...
[System.Xml.XmlDocument]$doc = 
       new-object System.Xml.XmlDocument;
    $doc.Load($strXMLFile);
    $root = $doc.get_DocumentElement();
    $root.Fruit.Metadata.AMS.Name = $strName
    $doc.Save($strXMLFile)

Though it is pretty much the same I also tried doing..
$xmlDoc = [XML](gc $strXMLFile) 
$xmldoc.Fruit.Metadata.AMS.Name = $strName
$xmldoc.Save($strXMLFile)

This save is changing more than the one tag I wanted it to. It is deleting few carriage returns and appending this weird [] to my DOCTYPE.. I don't understand why it is doing it and don't know the downward impact on systems that consume this XML. 
<!DOCTYPE ADI SYSTEM "ADI.DTD">

to
<!DOCTYPE ADI SYSTEM "ADI.DTD"[]>

Any inputs is appreciated

A: To keep the carriage returns try setting this property before saving:
$xmlDoc.PreserveWhitespace = $true

The square brackets are valid XML and shouldn't have any negative effect. See this SO question: 
XmlDocument.Save() inserts empty square brackets in doctype declaration
