Iczer Posted February 2, 2014 Share Posted February 2, 2014 As title says - How to make freshly baked XML nicely aligned? Without using Regexp, or anything of sort as it (nice align) would be ruined after first write to XML-file. expandcollapse popup$oXML_PatternNames = ObjCreate("Msxml2.DOMDocument.6.0") $oXMLDeclaration = $oXML_PatternNames.createProcessingInstruction ("xml", "version=""1.0"" encoding=""UTF-8""") $oXML_PatternNames.appendChild ($oXMLDeclaration) $oRoot = $oXML_PatternNames.createElement ("ListDefaults") $oRoot.setAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance") $oRoot.setAttribute("xmlns:xsd","http://www.w3.org/2001/XMLSchema") $oRoot.setAttribute("Name","") $oRoot.setAttribute("Key","0") $oRoot.setAttribute("Value","txt") $oXML_PatternNames.appendChild($oRoot) For $i = 1 To 7 ConsoleWrite ( $i &@crlf) $oChild = $oXML_PatternNames.createElement ("Pattern") $oChild.CreateAttribute("Name") $oChild.SetAttribute("Name","asdasdasd") $oChild.CreateAttribute("Key") $oChild.SetAttribute("Key","78") $oChild.CreateAttribute("Value") $oChild.SetAttribute("Value","txt") $oRoot.AppendChild($oChild) Next ConsoleWrite ( "RAW -------------------------------------------" &@crlf) ConsoleWrite ( $oXML_PatternNames.xml&@crlf) $tXML_PatternNames = StringRegExpReplace($oXML_PatternNames.xml,"><",">"&@crlf&"<") $tXML_PatternNames = StringRegExpReplace($tXML_PatternNames,"<Pattern"," <Pattern") $oXML_PatternNames = ObjCreate("Msxml2.DOMDocument.6.0") $oXML_PatternNames.LoadXML($tXML_PatternNames) ConsoleWrite ( "REGEXP ----------------------------------------" &@crlf) ConsoleWrite ( $oXML_PatternNames.xml&@crlf) $oChild = $oXML_PatternNames.createElement ("Pattern") $oChild.CreateAttribute("Name") $oChild.SetAttribute("Name","fffffffffff") $oChild.CreateAttribute("Key") $oChild.SetAttribute("Key","77") $oChild.CreateAttribute("Value") $oChild.SetAttribute("Value","txq") $oXML_PatternNames.selectSingleNode("ListDefaults").AppendChild($oChild) ConsoleWrite ( "ADD some element ------------------------------" &@crlf) ConsoleWrite ( $oXML_PatternNames.xml&@crlf) On a side note - why this script crash in 3.3.8.1, but work fine on 3.3.10.2 ? test_421.au3 (15) : ==> The requested action with this object has failed.: 1 $oChild.CreateAttribute("Name") $oChild.CreateAttribute("Name")^ ERROR Link to comment Share on other sites More sharing options...
Neutro Posted February 2, 2014 Share Posted February 2, 2014 Hey Iczer, It might be easier for other people to understand if you explain what you are trying to achieve first I tried compiling your script but i'm getting this error: C:\Users\Kev\Desktop\test.au3 (27) : ==> The requested action with this object has failed.: $oChild.CreateAttribute("Name") $oChild.CreateAttribute("Name")^ ERROR Identify active network connections and change DNS server - Easily export Windows network settings Clean temporary files from Windows users profiles directories - List Active Directory Groups members Export content of an Outlook mailbox to a PST file - File patch manager - IRC chat connect example Thanks again for your help Water! Link to comment Share on other sites More sharing options...
trancexx Posted February 2, 2014 Share Posted February 2, 2014 Maybe like this: ;... ConsoleWrite("RAW -------------------------------------------" & @CRLF) ConsoleWrite($oXML_PatternNames.xml & @CRLF) Local $oReader = ObjCreate("MSXML2.SAXXMLReader") Local $oWriter = ObjCreate("MSXML2.MXXMLWriter") $oWriter.indent = True ; this is it $oReader.contentHandler = $oWriter $oReader.parse($oXML_PatternNames.xml) $sFormatted = $oWriter.output ConsoleWrite("FORMATTED -------------------------------------------" & @CRLF) ConsoleWrite($sFormatted & @CRLF) ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Iczer Posted February 2, 2014 Author Share Posted February 2, 2014 (edited) Hey Iczer, It might be easier for other people to understand if you explain what you are trying to achieve first all i want is to make xml-file maintain human readable form after write in it. Preferably automatically. I tried compiling your script but i'm getting this error: C:\Users\Kev\Desktop\test.au3 (27) : ==> The requested action with this object has failed.: $oChild.CreateAttribute("Name") $oChild.CreateAttribute("Name")^ ERROR yeah, as it stated in op topic Edited February 2, 2014 by Iczer Link to comment Share on other sites More sharing options...
Neutro Posted February 2, 2014 Share Posted February 2, 2014 Sorry I didn't see this at first doh! I'm not very good at COM dev so can't help you much on this one! Identify active network connections and change DNS server - Easily export Windows network settings Clean temporary files from Windows users profiles directories - List Active Directory Groups members Export content of an Outlook mailbox to a PST file - File patch manager - IRC chat connect example Thanks again for your help Water! Link to comment Share on other sites More sharing options...
Iczer Posted February 2, 2014 Author Share Posted February 2, 2014 Maybe like this: ;... Wow Thanks! But why i get crush on 3.3.8.1? Link to comment Share on other sites More sharing options...
trancexx Posted February 2, 2014 Share Posted February 2, 2014 Because in 3.3.8.1 there are some bugs that are fixed in newer versions. The process is called developing. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Iczer Posted February 2, 2014 Author Share Posted February 2, 2014 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now