Jump to content

XML DOM wrapper (COM)


eltorro
 Share

Recommended Posts

Well you have to consider certain things. What are you grouping by? How will you read it back out later?

If you do it like this it may be a pain in the ass to get usable results later:

<?xml version="1.0" encoding="utf-8"?>
<Event_Log>
  <TestLog ID="0001">
    <Type>xxxx</Type>
    <Message>xxxx</Message>
    <Time>xxxx</Time>
    <Picture>xxxx</Picture>
    <Remarks>xxxx</Remarks>
  </TestLog>
  <TestLog ID="0002">
    <Type>xxxx</Type>
    <Message>xxxx</Message>
    <Time>xxxx</Time>
    <Picture>xxxx</Picture>
    <Remarks>xxxx</Remarks>
  </TestLog>
  <Group>
    <TestLog ID="0003">
        <Type>xxxx</Type>
        <Message>xxxx</Message>
        <Time>xxxx</Time>
        <Picture>xxxx</Picture>
        <Remarks>xxxx</Remarks>
      </TestLog>
    <TestLog ID="0004">
        <Type>xxxx</Type>
        <Message>xxxx</Message>
        <Time>xxxx</Time>
        <Picture>xxxx</Picture>
        <Remarks>xxxx</Remarks>
      </TestLog>
  </Group>
</Event_Log>

I have never seen a log file "group" entries together so maybe using an attribute would be more helpful than nesting nodes.

Link to comment
Share on other sites

Well this is confusing... I figured XML would be the best way to do this.

I have an XML file set up like so:

<CamList>
    <Andorra>
        <Camera>
            <Name>Eric el viking 1</Name>
            <Description>WebCam over Andorra</Description>
            <ImageURL>http://www.andorracam.info/left.jpg</ImageURL>
            <PageURL>http://www.andorracam.info/cam.html</PageURL>
        </Camera>
        <Camera>
            <Name>Eric el viking 2</Name>
            <Description>WebCam over Andorra</Description>
            <ImageURL>http://www.andorracam.info/right.jpg</ImageURL>
            <PageURL>http://www.andorracam.info/cam.html</PageURL>
        </Camera>
    </Andorra>
    <Antarctica>
        <Camera>
            <Name>Scott Base</Name>
            <Description>Scott Base Webcam</Description>
            <ImageURL>http://www.antarcticanz.govt.nz/webcam/webcam32.jpg</ImageURL>
            <PageURL>http://www.antarcticanz.govt.nz/education/2568</PageURL>
        </Camera>
        <Camera>
            <Name>Neumayer-Station</Name>
            <Description>View from the westerly tower to the base.</Description>
            <ImageURL>http://www.awi.de/NM_WebCam/neumayer.last.jpg</ImageURL>
            <PageURL>http://www.awi-bremerhaven.de/NM_WebCam/</PageURL>
        </Camera>
    </Antarctica>
</CamList>

I wish to have it output into an array (no idea whats the best way to output it.

The way I'm going, I will have thousands of cameras.... :)

So any ideas on the best way to return an array of each data, or should I look at using SQLite for storing my data?

EDIT: Solved! I think... :lmao:

#include <_XMLDomWrapper.au3>
#include <Array.au3>

Dim $rArray[1][1]

_XMLFileOpen("CamList.xml")
$array = _XMLGetChildren("CamList")
$rArray[0][0] = $array[0][0]
ReDim $rArray[$array[0][0] + 1][1]

For $i = 1 To $array[0][0]
    $array1 = _XMLGetChildren("CamList/" & $array[$i][0])
    $number = $array1[0][0]

    ReDim $rArray[$array[0][0] + 1][(($number * 4) + 1) + 1]

    $rArray[$i][0] = $array[$i][0]
    $rArray[$i][1] = $number
    For $x = 1 To $number
        $name = _XMLGetValue("/CamList/" & $array[$i][0] & "/Camera[" & $x & "]/Name")
        If Not @error Then $name = $name[1]
        $desc = _XMLGetValue("/CamList/" & $array[$i][0] & "/Camera[" & $x & "]/Description")
        If Not @error Then $desc = $desc[1]
        $img = _XMLGetValue("/CamList/" & $array[$i][0] & "/Camera[" & $x & "]/ImageURL")
        If Not @error Then $img = $img[1]
        $path = _XMLGetValue("/CamList/" & $array[$i][0] & "/Camera[" & $x & "]/PageURL")
        If Not @error Then $path = $path[1]
        $rArray[$i][(($x * 4) + 1) - 3] = $name
        $rArray[$i][(($x * 4) + 2) - 3] = $desc
        $rArray[$i][(($x * 4) + 3) - 3] = $img
        $rArray[$i][(($x * 4) + 4) - 3] = $path
    Next
;_ArrayDisplay ($array1)
Next

_ArrayDisplay($rArray)

MsgBox(0, "", "Name: " & $rArray[1][2] & @CRLF & _
        "Desc: " & $rArray[1][3] & @CRLF & _
        "Image: " & $rArray[1][4] & @CRLF & _
        "Path: " & $rArray[1][5] & @CRLF)
;   [0][0] = Countries
;   [1][0] = Country Name
;   [1][1] = Number Cameras
;   [1][2] = Camera 1 Name
;   [1][3] = Camera 1 Description
;   [1][4] = Camera 1 Image
;   [1][5] = Camera 1 Path
;   [1][6] = Camera 2 Name
;   [1][7] = Camera 2 Description
;   [1][8] = Camera 2 Image
;   [1][9] = Camera 2 Path
;   [n][n] = Countries n etc.
Edited by BrettF
Link to comment
Share on other sites

Hi!

First I would like to say thank you for your excellent UDF!!! It works fantastic!!!

I'm re-writing a script (CMD -> AU3). Somewhere in the old script I have

to generate an output from a XML file by using an MSXSL.EXE and a XSL transform.

Sure, I could use Run() and grap StdOut. But I would like to do it better. :-)

So, is there a way to realize the same result with your UDF? Here's the XSL transform:

<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="UTF-8"/>

<xsl:template match="*">
  <xsl:choose>
    <xsl:when test="name()='FileLocation'">
      <xsl:if test="contains(@Url, '/windowsxp') and contains(@Url, '-x86-') and contains(@Url, '-deu') and contains(@Url, '.exe')">
        <xsl:value-of select="@Url"/>
        <xsl:text>
</xsl:text>
      </xsl:if>
      <xsl:if test="contains(@Url, '/ie7') and contains(@Url, 'windowsxp') and contains(@Url, '-x86-') and contains(@Url, '-deu') and contains(@Url, '.exe')">
        <xsl:value-of select="@Url"/>
        <xsl:text>
</xsl:text>
      </xsl:if>
    </xsl:when>
    <xsl:otherwise>
      <xsl:apply-templates select="*"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

</xsl:transform>

By the way: The last update of your UDFs are from mid 2008. Is there a new version?

Thank you!

Greets,

-supersonic.

I've needed these for a while and didn't find any suitable so here's what I came up with.

_XMLDomWrapper.au3

Edit: Updated Version 03.07.2008 (Version 1.0.3.87) Total downloads: Posted Image

Edit: MDI Version 3.2.2006

CODE
_XMLCreateFile($sPath, $sRootNode, [$bOverwrite = False]) Creates an XML file with the given name and root.(Requires: #include <_XMLDomWrapper.au3>)

_XMLFileOpen($sXMLFile,[$sNamespace=""],[$ver=-1]) Creates an instance of an XML file.(Requires: #include <_XMLDomWrapper.au3>)

;==============================================================================

_XMLGetChildNodes ( strXPath ) Selects XML child Node(s) of an element based on XPath input from root node. (Requires: #include <_XMLDomWrapper.au3>)

_XMLGetNodeCount ( strXPath, strQry = "", iNodeType = 1 ) Get node count for specified path and type. (Requires: #include <_XMLDomWrapper.au3>)

_XMLGetPath ( strXPath ) Returns a nodes full path based on XPath input from root node. (Requires: #include <_XMLDomWrapper.au3>)

;==============================================================================

_XMLSelectNodes ( strXPath ) Selects XML Node(s) based on XPath input from root node. (Requires: #include <_XMLDomWrapper.au3>)

_XMLGetField ( strXPath ) Get XML Field(s) based on XPath input from root node.(Requires: #include <_XMLDomWrapper.au3>)

_XMLGetValue ( strXPath ) Get XML Field based on XPath input from root node. (Requires: #include <_XMLDomWrapper.au3>)

_XMLGetChildText ( strXPath ) Selects XML child Node(s) of an element based on XPath input from root node. (Requires: #include <_XMLDomWrapper.au3>)

_XMLUpdateField ( strXPath, strData ) Update existing node(s) based on XPath specs.(Requires: #include <_XMLDomWrapper.au3>)

_XMLReplaceChild ( objOldNode, objNewNode, ns = "" ) Replaces a node with a new node. (Requires: #include <_XMLDomWrapper.au3>)

;==============================================================================

_XMLDeleteNode ( strXPath ) Delete specified XPath node.(Requires: #include <_XMLDomWrapper.au3>)

_XMLDeleteAttr ( strXPath, strAttrib ) Delete attribute for specified XPath(Requires: #include <_XMLDomWrapper.au3>)

_XMLDeleteAttrNode ( strXPath, strAttrib ) Delete attribute node for specified XPath(Requires: #include <_XMLDomWrapper.au3>)

;==============================================================================

_XMLGetAttrib ( strXPath, strAttrib, strQuery = "" ) Get XML attribute based on XPath input from root node.(Requires: #include <_XMLDomWrapper.au3>)

_XMLGetAllAttrib ( strXPath, ByRef aName, ByRef aValue, strQry = "" ) Get all XML Field(s) attributes based on XPath input from root node.(Requires: #include <_XMLDomWrapper.au3>)

_XMLGetAllAttribIndex ( strXPath, ByRef aName, ByRef aValue, strQry = "", NodeIndex = 0 ) Get all XML Field(s) attributes based on Xpathn and specific index.(Requires: #include <_XMLDomWrapper.au3>)

_XMLSetAttrib ( strXPath, strAttrib, strValue = "" ) Set XML Field(s) attributes based on XPath input from root node.(Requires: #include <_XMLDomWrapper.au3>)

;==============================================================================

_XMLCreateCDATA ( strNode, strCDATA, strNameSpc = "" ) Create a CDATA SECTION node directly under root. (Requires: #include <_XMLDomWrapper.au3>)

_XMLCreateComment ( strNode, strComment ) Create a COMMENT node at specified path.(Requires: #include <_XMLDomWrapper.au3>)

_XMLCreateAttrib ( strXPath,strAttrName,strAttrValue="" ) Creates an attribute for the specified node. (Requires: #include <_XMLDomWrapper.au3>)

;==============================================================================

_XMLCreateRootChild ( strNode, strData = "", strNameSpc = "" ) Create node directly under root.(Requires: #include <_XMLDomWrapper.au3>)

_XMLCreateRootNodeWAttr ( strNode, aAttr, aVal, strData = "", strNameSpc = "" ) Create a child node under root node with attributes.(Requires: #include <_XMLDomWrapper.au3>)

_XMLCreateChildNode ( strXPath, strNode, strData = "", strNameSpc = "" ) Create a child node under the specified XPath Node.(Requires: #include <_XMLDomWrapper.au3>)

_XMLCreateChildWAttr ( strXPath, strNode, aAttr, aVal, strData = "", strNameSpc = "" ) Create a child node under the specified XPath Node with Attributes. (Requires: #include <_XMLDomWrapper.au3>)

;==============================================================================

_XMLSchemaValidate ( sXMLFile, ns, sXSDFile ) _XMLSchemaValidate($sXMLFile, $ns, $sXSDFile) Validate a document against a DTD. (Requires: #include <_XMLDomWrapper.au3>)

_XMLGetDomVersion ( ) Returns the XSXML version currently in use. (Requires: #include <_XMLDomWrapper.au3>)

_XMLError ( sError = "" ) Sets or Gets XML error message generated by XML functions.(Requires: #include <_XMLDomWrapper.au3>)

_XMLUDFVersion ( ) eturns the UDF Version number. (Requires: #include <_XMLDomWrapper.au3>)

_XMLTransform ( oXMLDoc, Style = "",szNewDoc="" ) Transfroms the document using built-in sheet or xsl file passed to function. (Requires: #include <_XMLDomWrapper.au3>)

_XMLNodeExists( $strXPath) Checks for the existence of the specified path. (Requires: #include <_XMLDomWrapper.au3>)

Here's a sample prog to show some of its usefullness.

Its the gui sample from the /Examples/gui folder.

SaveSampleControls.au3

Works with newer wrapper :)

XmlExample.au3

_XMLExample.au3 downloads: Posted Image

The only thing I could not get to work was getting the checkbox state in the 2nd treeview.

Please give me some feedback.

Steve

Edit:

Bug Fix: _XMLGetField not returning array count.

Added Func _XMLSelectNodes($sXPath) returns a list of node names

Edit:

Corrected Def for _XMLGetAllAttrib

Edit:

Bugfix for _XMLCreateCDATA

Bugfix for _XMLGetValue returns array as supposed to.

Edit: June 29,2006

Added count to index[0] of the _XMLGetValue return

Change _XMLFileOpen _XMLFileCreate to look for available MSXML obj.

Added optional flag to _XMLFileCreate for specifiying UTF-8

Edit: March , Apr 2007

Mar 30, 2007 Rewrote _AddFormat function to break up tags( no indentation)

Added _XMLTransform() which runs the document against a xsl(t) style sheet for indentation.

Changed _XMLCreateRootChildWAttr() to use new formatting

Changed _XMLChreateChildNode() to use new formatting

Apr 02, 2007 Added _XMLReplaceChild()

Apr 03, 2007 Changed other node creating function to use new formatting

Changed _XMLFileOpen() _XMLFileCreate to take an optional version number of MSXML to use.

Changed _XMLFileOpen() _XMLFileCreate find latest MSXML version logic.

Edit: Apr 24, 25 2007

Fixed _XMLCreateChileNodeWAttr() - Instead of removal, It points to the function that replaced it.

Added _XMLCreateAttrib()

Fixed bug with _XMLCreateRootNodeWAttr ,_XMLCreateChild[Node]WAttr() where an extra node with same name was added.

Stripped extrenous comments.

Removed dependency on Array.au3 (I added the func from Array.au3 and renamed it to avoid conflicts.)

Edit: Jun 8, 2007

Fixed a namespace bug in _XMLCreateChildNode() and _XMLCreateChildNodeWAttr()

Edit: July 12, 2007

Changed version number displayed on this page to reflect latest version.

Edit: July 13, 2007

Fixed example script.

Edit: July 20, 2007

Fixed a bug where a failed _XMLFileOpen() return an empty object

Added an object check to applicable functions.

Edit: Aug 8, 2007

Added _XMLSetAutoSave() to turn off/on forced saving. -- Thanks drlava.

Added check for previous creation of COM error handler. --Thanks Lukasz Suleja

Edit: Aug 27, 2007

Changed order of properties created on file open to correct behaviour with namespaces.

Edit: Aug 31,2007

Fixed bug where _XMLUpdatedField would inadvertantly erase child nodes.

Edit: Sep 07,2007

Fixed _XMLDeleteNode bug where non-existant node cause COM error.

Added _XMLNodeExist function to check for the existence of node or nodes matching the specified path

Edit: Jan 05,2008

Fixed header documentation for _XMLGetAttrib. It returns the requested attribute if found. Not an array.

Edit: Feb 25,2008

Fixed dimensioning bug in _XMLGetChildren --Thanks oblique

Edit: Mar 05,2008

Return values fixed for the following functions: --Thanks oblique

_XMLFileOpen ,_XMLLoadXML,_XMLCreateFile

Documentation fixed for _XMLGetNodeCount,_XMLGetChildren --Thanks oblique

Edit: Mar 07,2008

Small changes.

Fixed an issue pointed out by lgr.

** latest version 1.0.3.87 ** Total downloads: Posted Image

Edited by supersonic
Link to comment
Share on other sites

First thing, why did you quote the first post? Eltorro doesn't really come around any more.

Second, in the function list you will find _XMLTransform which there are a few examples of in this topic.

Link to comment
Share on other sites

I am relatively new to XML that is in manipulating it and such. I basically have need to be able to pull the XML data from a database, parse it get the information I want out, and write it back to the database. I know how to do the read and write of the database so don't think I am asking that here. I am simply wondering if there's a manner whereby I can simply process XML from a string versus a file without having to write a temporary file to the hard drive? Then also output back to a string. Inside _XMLDOMWrapper.au3, I found _XMLLoadXML($strXML) It somewhat seems to do what I would want, but I am unable to determine by looking at the function if it is what I need.

Please let me know if anyone can assist...

Thanks,

Jarvis

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

You sir are correct and already answered your own question. That function should do what you need it to.

Thanks a ton. So that does do it then... Does it return a handle or anything else whereby I can start accessing the data? I don't see a proper return that would indicate I can use it once it's loaded the string. Also how would I get a modified string back out? Or would it just modify it in my variable?

Thanks,

Jarvis

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Here is an example.

#include "..\_XMLDomWrapper.au3"

;$sXMLFile = "colors.xml"

$bXMLAUTOSAVE = false

$string = '<?xml version="1.0" encoding="utf-8"?>' & _
'<colors>' & _
    '<color name="Red" hex="0x"/>' & _
    '<color name="Blue" hex="0x"/>' & _
    '<color name="Green" hex="0x"/>' & _
'</colors>'

_XMLLoadXML($string)

;$result = _XMLFileOpen($sXMLFile)
;If $result = 0 Then Exit

$path = "//colors"

;Retrieve all subnodes of "Keys" (used for count)
$nodesArray = _XMLGetChildNodes($path)
For $X = 1 to $nodesArray[0]
    ConsoleWrite(_XMLGetAttrib($path & "/color[" & $X & "]", "name") & " " & _XMLGetAttrib($path & "/color[" & $X & "]", "hex")  & @CRLF)
Next

;Set attribute for specific element (in the example we have 3 elements)
_XMLSetAttrib($path & "/color[@name='Red']", "hex", "0xFF0000")
_XMLSetAttrib($path & "/color[@name='Blue']", "hex", "0x0000FF")
_XMLSetAttrib($path & "/color[@name='Green']", "hex", "0x00FF00")

;Retrieve all subnodes of "Keys" (used for count)
$nodesArray = _XMLGetChildNodes($path)
For $X = 1 to $nodesArray[0]
    ConsoleWrite(_XMLGetAttrib($path & "/color[" & $X & "]", "name") & " " & _XMLGetAttrib($path & "/color[" & $X & "]", "hex")  & @CRLF)
Next

ConsoleWrite($objDoc.xml & @CRLF)
Link to comment
Share on other sites

Here is an example.

#include "..\_XMLDomWrapper.au3"

;$sXMLFile = "colors.xml"

$bXMLAUTOSAVE = false

$string = '<?xml version="1.0" encoding="utf-8"?>' & _
'<colors>' & _
    '<color name="Red" hex="0x"/>' & _
    '<color name="Blue" hex="0x"/>' & _
    '<color name="Green" hex="0x"/>' & _
'</colors>'

_XMLLoadXML($string)

;$result = _XMLFileOpen($sXMLFile)
;If $result = 0 Then Exit

$path = "//colors"

;Retrieve all subnodes of "Keys" (used for count)
$nodesArray = _XMLGetChildNodes($path)
For $X = 1 to $nodesArray[0]
    ConsoleWrite(_XMLGetAttrib($path & "/color[" & $X & "]", "name") & " " & _XMLGetAttrib($path & "/color[" & $X & "]", "hex")  & @CRLF)
Next

;Set attribute for specific element (in the example we have 3 elements)
_XMLSetAttrib($path & "/color[@name='Red']", "hex", "0xFF0000")
_XMLSetAttrib($path & "/color[@name='Blue']", "hex", "0x0000FF")
_XMLSetAttrib($path & "/color[@name='Green']", "hex", "0x00FF00")

;Retrieve all subnodes of "Keys" (used for count)
$nodesArray = _XMLGetChildNodes($path)
For $X = 1 to $nodesArray[0]
    ConsoleWrite(_XMLGetAttrib($path & "/color[" & $X & "]", "name") & " " & _XMLGetAttrib($path & "/color[" & $X & "]", "hex")  & @CRLF)
Next

ConsoleWrite($objDoc.xml & @CRLF)
Thanks a ton. That helps me a out a ton!

Jarvis

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Well you have to consider certain things. What are you grouping by? How will you read it back out later?

....

Hi Weaponx,

After considering on the comments from your reply, I have made some changes to my UDF. I'm now using a child element to store my folder structure. This is the code I have come out with. I have tried not to generate a recurrsive kind of xml structure in my UDF as I'm still not familiar with it yet.

I would like to know based on this kind of approach, can I still create an xsl + js to display my data in folder-tree layout? My expected layout on the web browser would be something like this: XmlTreeLoader

I know that I'm also asking for too much. As I'm not expert in XSL and JS, if possible, can you direct me to any references for this kind of xsl example? As I have search thru the web for past few days with no matching solution to my kind of xml implementation.

Thanks again for your great help.

#Include "Date.au3"
#include "_XMLDomWrapper.au3"
;===============================================================================
; Version 1.01
; UDF Name: _CTL_TestLog.au3
; Requirement:  AutoIT 3.3 or later
; Include:      "_XMLDomWrapper.au3", "Date.au3"                
;===============================================================================
;[Function Local Variable]
;_TestLog_Initiate()
Dim $s_xroot
Dim $s_xtree
;_TestLog_Message()
Dim $s_XMLFile
;===============================================================================
;===============================================================================
; Function Name:    _TestLog_Initiate($s_Path)
; Category:         Initiate, Test Log
; Description::     Create XML testlog template for logging.
; Parameter(s):     [$s_XMLFile] - full path of test log file 
; Requirement(s):   #include <"_XMLDomWrapper.au3">
; Return Value(s):  $s_xroot contains root xpath "//Test_Log".
;                   4s_xtree contains the virtual folder structure
;                   $s_XMLFile contains current working XML file.
; Author(s):        Peter Yeung   13 Jan 2009
;                   Peter Yeung   23 Jan 2009
; Bugs:             Overwrite existing test log file if exists
;                   Create xml root node "//Test_Log"
;                   Support for virtual folder structure into <Dir> tag
;===============================================================================

Func _TestLog_Initiate($s_Path)

    ;Create file (force overwrite existing file)
    $result = _XMLCreateFile($s_Path, "Test_Log", 1)

    Switch @error
        Case 0 
            ;"No error"
        Case 1 
            MsgBox(0,"_TestLog_Initiate()","Failed to create file")
        Case 2 
            MsgBox(0,"_TestLog_Initiate()","No object")
        Case 3 
            MsgBox(0,"_TestLog_Initiate()","File creation failed MSXML error")
        Case 4 
            MsgBox(0,"_TestLog_Initiate()","File exists")
    EndSwitch

    $s_xroot = "//Test_Log"         ;xpath
    $s_xtree = ""                   ;virtual folder structure
    $s_XMLFile = $s_Path            ;XML file
    
EndFunc

;===============================================================================
; Function Name:    _TestLog_Message($s_Path)
; Category:         Message, Test Log
; Description::     Posting message into test log.
; Parameter(s):     [$s_message] - string for [Message] tag.
;                   [$s_remarks] - string for [Remarks] tag.
; Requirement(s):   #include <_XMLDomWrapper.au3>, #Include <Date.au3>
;                   Func _Testlog_Initiate()
;                   Dim $s_xroot, Dim $s_xtree, Dim $s_XMLFile
; Return Value(s):  update $s_xroot if node is empty
; Author(s):        Peter Yeung   13 Jan 2009
;                   Peter Yeung   22 Jan 2009
; Bugs:             Create 1st node element if no node is available
;                   Auto input DateTime in [Time] tag 
;                   [ID Type =] attribute set to "Message"
;                   Support for virtual folder structure into <Dir> tag
;===============================================================================

Func _TestLog_Message($s_message, $s_remarks)
    
    ; Record posting time
    $tCur = _Date_Time_GetLocalTime()
    
    ; Open XML file
    $result = _XMLFileOpen($s_XMLFile)
    If $result = 0 Then 
        MsgBox(0,"_TestLog_Message()","File not found")
        Exit
    EndIf

    ; Check if last node is available
    $result = _XMLSelectNodes($s_xroot & "/Log[last()]")
    If $result = -1 Then
        ; Create new child entry 
        _XMLCreateRootChild ("Log", "")
        _XMLSetAttrib($s_xroot & "/Log[1]", "ID", StringFormat("%04s",1))  ;convert to string, pad to 4 characters (4 digits)
        _XMLSetAttrib($s_xroot & "/Log[1]", "Type", "Message") 
        ;$s_xtree = $s_xroot & "/Log"
        _XMLCreateChildNode ($s_xroot & "/Log[1]", "Dir", $s_xtree)
        _XMLCreateChildNode ($s_xroot & "/Log[1]", "Time", _Date_Time_SystemTimeToDateTimeStr($tCur))
        _XMLCreateChildNode ($s_xroot & "/Log[1]", "Message", $s_message)
        _XMLCreateChildNode ($s_xroot & "/Log[1]", "Remarks", $s_remarks)
        _XMLCreateChildNode ($s_xroot & "/Log[1]", "Picture", "")
        
    Else
        ; Get last entry id
        $result = Number(_XMLGetAttrib($s_xroot & "/Log[last()]", "ID"))
        ; Append new child entry 
        _XMLCreateRootChild ("Log", "")
        _XMLSetAttrib($s_xroot & "/Log[last()]", "ID", StringFormat("%04s",$result+1)) ;Increment, convert to string, pad to 4 characters (4 digits)
        _XMLSetAttrib($s_xroot & "/Log[last()]", "Type", "Message") 
        _XMLCreateChildNode ($s_xroot & "/Log[last()]", "Dir", $s_xtree)
        _XMLCreateChildNode ($s_xroot & "/Log[last()]", "Time", _Date_Time_SystemTimeToDateTimeStr($tCur))
        _XMLCreateChildNode ($s_xroot & "/Log[last()]", "Message", $s_message)
        _XMLCreateChildNode ($s_xroot & "/Log[last()]", "Remarks", $s_remarks)
        _XMLCreateChildNode ($s_xroot & "/Log[last()]", "Picture", "")
        
    EndIf
    
EndFunc

;===============================================================================
; Function Name:    _TestLog_Folder($s_ctrl, $s_title, $s_remarks)
; Category:         Folder, Test Log
; Description::     Create Folder layout for test log posting.
; Parameter(s):     [$s_ctrl] - "Open" / "Close"
;                   [$s_title] - string for [Message] tag.
;                   [$s_remarks] - string for [Remarks] tag.
; Requirement(s):   #include <_XMLDomWrapper.au3>
;                   _Testlog_Initiate()
;                   Dim $s_xroot, Dim $s_xtree, Dim $s_XMLFile
; Return Value(s):  update $s_xtree
; Author(s):        Peter Yeung   22 Jan 2009
; Bugs:             Required to call for "Close" ctrl whenever postings is completed for the targeted folder.
;                   [/aaa/bbb/ccc] folder syntax structure for <Dir> tag
;                   Indicate ["Folder"] in [ID type] attribute
;===============================================================================
Func _TestLog_Folder($s_ctrl, $s_title, $s_remarks)
    
    ; Record posting time
    $tCur = _Date_Time_GetLocalTime()
    
    ; Open XML file
    $result = _XMLFileOpen($s_XMLFile)
    If $result = 0 Then 
        MsgBox(0,"_TestLog_Folder()","File not found")
        Exit
    EndIf

    ; Check if last node is available
    $result = _XMLSelectNodes($s_xroot & "/Log[last()]")
    If $result = -1 Then
        ; For empty [/TestLog] tree
        If $s_ctrl = "Open" Then
            ; Create new node element directly under the root 
            _XMLCreateRootChild ("Log", "")
            _XMLSetAttrib($s_xroot & "/Log[1]", "ID", StringFormat("%04s",1))  
            _XMLSetAttrib($s_xroot & "/Log[1]", "Type", "Folder")  
            $s_xtree = $s_xtree & "/" & $s_title
            _XMLCreateChildNode ($s_xroot & "/Log[1]", "Dir", $s_xtree)
            _XMLCreateChildNode ($s_xroot & "/Log[1]", "Time", _Date_Time_SystemTimeToDateTimeStr($tCur))
            _XMLCreateChildNode ($s_xroot & "/Log[1]", "Message", $s_title)
            _XMLCreateChildNode ($s_xroot & "/Log[1]", "Remarks", $s_remarks)
            _XMLCreateChildNode ($s_xroot & "/Log[1]", "Picture", "")

        ElseIf $s_ctrl = "Close" Then
            ; Do nothing
        EndIf   
    Else
        ;For existing [/TestLog] tree
        If $s_ctrl = "Open" Then
            ; Get last entry id
            $result = Number(_XMLGetAttrib($s_xroot & "/Log[last()]", "ID"))
            ; Append to node element
            _XMLCreateRootChild ("Log", "")
            _XMLSetAttrib($s_xroot & "/Log[last()]", "ID", StringFormat("%04s",$result+1))
            _XMLSetAttrib($s_xroot & "/Log[last()]", "Type", "Folder") 
            $s_xtree = $s_xtree & "/" & $s_title
            _XMLCreateChildNode ($s_xroot & "/Log[last()]", "Dir", $s_xtree)
            _XMLCreateChildNode ($s_xroot & "/Log[last()]", "Time", _Date_Time_SystemTimeToDateTimeStr($tCur))
            _XMLCreateChildNode ($s_xroot & "/Log[last()]", "Message", $s_title)
            _XMLCreateChildNode ($s_xroot & "/Log[last()]", "Remarks", $s_remarks)  
            _XMLCreateChildNode ($s_xroot & "/Log[last()]", "Picture", "")          
            
        ElseIf $s_ctrl = "Close" Then
            ; Remove xtree path element by 1 level up
            $s_xtreename = StringSplit($s_xtree, "/")
            ; If Not $s_xtreename[UBound($s_xtreename) - 1] = $s_xroot Then     
            If $s_xtree = $s_xroot Then 
                ;No need to remove path level for root path
            Else    
                $s_xtree = StringReplace($s_xtree, "/" & $s_xtreename[UBound($s_xtreename) - 1], "")
            EndIf

        EndIf

    EndIf
    
EndFunc
;----------------------------------End of Code----------------------------------
;Code example:
$TempXML = @ScriptDir & "\example.xml"
_TestLog_Initiate($TempXML)
_TestLog_Message("Testing...1", "Testing...1")                  
_TestLog_Message("Testing...2", "Testing...2")                  
_TestLog_Folder("Open", "Folder...1", "Folder...1")             ;[Root]:/Folder...1
    _TestLog_Message("Testing...3", "Testing...3")
_TestLog_Folder("Close", "", "")
_TestLog_Folder("Open", "Folder...2", "Folder...2")             ;[Root]:/Folder...2
    _TestLog_Message("Testing...4", "Testing...4")
_TestLog_Folder("Close", "", "")
_TestLog_Message("Testing...5", "Testing...5")
_TestLog_Folder("Open", "Folder...3", "Folder...3")             ;[Root]:/Folder...3
    _TestLog_Message("Testing...6", "Testing...6")
    _TestLog_Folder("Open", "Folder...3a", "Folder...3a")       ;[Root]:/Folder...3/Folder...3a
        _TestLog_Message("Testing...7", "Testing...7")
    _TestLog_Folder("Close", "", "")
    _TestLog_Message("Testing...8", "Testing...8")
_TestLog_Folder("Close", "", "")
_TestLog_Message("Testing...9", "Testing...9")oÝ÷ Ø̨ºÚnµsjëh×6<?xml version="1.0" ?> 
- <Test_Log>
- <Log ID="0001" Type="Message">
  <Dir /> 
  <Time>01/23/2009 10:42:27</Time> 
  <Message>Testing...1</Message> 
  <Remarks>Testing...1</Remarks> 
  <Picture /> 
  </Log>
- <Log ID="0002" Type="Message">
  <Dir /> 
  <Time>01/23/2009 10:42:27</Time> 
  <Message>Testing...2</Message> 
  <Remarks>Testing...2</Remarks> 
  <Picture /> 
  </Log>
- <Log ID="0003" Type="Folder">
  <Dir>/Folder...1</Dir> 
  <Time>01/23/2009 10:42:27</Time> 
  <Message>Folder...1</Message> 
  <Remarks>Folder...1</Remarks> 
  <Picture /> 
  </Log>
- <Log ID="0004" Type="Message">
  <Dir>/Folder...1</Dir> 
  <Time>01/23/2009 10:42:27</Time> 
  <Message>Testing...3</Message> 
  <Remarks>Testing...3</Remarks> 
  <Picture /> 
  </Log>
- <Log ID="0005" Type="Folder">
  <Dir>/Folder...2</Dir> 
  <Time>01/23/2009 10:42:27</Time> 
  <Message>Folder...2</Message> 
  <Remarks>Folder...2</Remarks> 
  <Picture /> 
  </Log>
- <Log ID="0006" Type="Message">
  <Dir>/Folder...2</Dir> 
  <Time>01/23/2009 10:42:27</Time> 
  <Message>Testing...4</Message> 
  <Remarks>Testing...4</Remarks> 
  <Picture /> 
  </Log>
- <Log ID="0007" Type="Message">
  <Dir /> 
  <Time>01/23/2009 10:42:28</Time> 
  <Message>Testing...5</Message> 
  <Remarks>Testing...5</Remarks> 
  <Picture /> 
  </Log>
- <Log ID="0008" Type="Folder">
  <Dir>/Folder...3</Dir> 
  <Time>01/23/2009 10:42:28</Time> 
  <Message>Folder...3</Message> 
  <Remarks>Folder...3</Remarks> 
  <Picture /> 
  </Log>
- <Log ID="0009" Type="Message">
  <Dir>/Folder...3</Dir> 
  <Time>01/23/2009 10:42:28</Time> 
  <Message>Testing...6</Message> 
  <Remarks>Testing...6</Remarks> 
  <Picture /> 
  </Log>
- <Log ID="0010" Type="Folder">
  <Dir>/Folder...3/Folder...3a</Dir> 
  <Time>01/23/2009 10:42:29</Time> 
  <Message>Folder...3a</Message> 
  <Remarks>Folder...3a</Remarks> 
  <Picture /> 
  </Log>
- <Log ID="0011" Type="Message">
  <Dir>/Folder...3/Folder...3a</Dir> 
  <Time>01/23/2009 10:42:29</Time> 
  <Message>Testing...7</Message> 
  <Remarks>Testing...7</Remarks> 
  <Picture /> 
  </Log>
- <Log ID="0012" Type="Message">
  <Dir>/Folder...3</Dir> 
  <Time>01/23/2009 10:42:29</Time> 
  <Message>Testing...8</Message> 
  <Remarks>Testing...8</Remarks> 
  <Picture /> 
  </Log>
- <Log ID="0013" Type="Message">
  <Dir /> 
  <Time>01/23/2009 10:42:29</Time> 
  <Message>Testing...9</Message> 
  <Remarks>Testing...9</Remarks> 
  <Picture /> 
  </Log>
  </Test_Log>
Link to comment
Share on other sites

@VAG - If you look at one of my older posts you will find an example using a tree structrure

#359059

The node types are "items" and "folders". The XML is generated by an AutoIt script:

Pre-transformation:

<?xml version="1.0"?>
 <menu>
   <folder name="Spyware" oscode="255">
     <folder name="Install" oscode="255">
       <folder name="Silent" oscode="255">
         <item name="Great-Grandchild item" target="PATH\TO\PROGRAM.EXE" oscode="255"/>
       </folder>
       <item name="Grandchild item" target="PATH\TO\PROGRAM.EXE" oscode="255"/>
     </folder>
     <item name="Child item" target="PATH\TO\PROGRAM.EXE" oscode="255"/>
     <folder name="TEST" oscode="255">
       <item name="Great-Grandchild item" target="PATH\TO\PROGRAM.EXE" oscode="255"/>
     </folder>
   </folder>
   <item name="Root item" target="PATH\TO\PROGRAM.EXE" oscode="255"/>
   <folder name="Antivirus" oscode="255">
     <item name="Another child item" target="PATH\TO\PROGRAM.EXE" oscode="255"/>
   </folder>
 </menu>

After this an XSL transformation is applied which sorts alphabetically and moves folders to the beginning like Windows Explorer.

Config.xsl:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method="xml" version="1.0" encoding="iso-8859-1" indent="yes"/>

    <xsl:template match="/menu">
        <menu>
            <xsl:apply-templates select="item | folder">
                <xsl:sort select="name()"/>
                <xsl:sort select="@name" data-type="text"/>
            </xsl:apply-templates>
        </menu>
    </xsl:template>

    <xsl:template match="item | folder">
        <xsl:copy>
            <xsl:copy-of select="namespace::*|@*"/>
            <xsl:apply-templates select="item | folder">
                <xsl:sort select="name()"/>
                <xsl:sort select="@name" data-type="text"/>
            </xsl:apply-templates>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

Post-transformation:

<?xml version="1.0" encoding="iso-8859-1"?>
 <menu>
     <folder name="Antivirus" oscode="255">
         <item name="Another child item" target="PATH\TO\PROGRAM.EXE" oscode="255"></item>
     </folder>
     <folder name="Spyware" oscode="255">
         <folder name="Install" oscode="255">
             <folder name="Silent" oscode="255">
                 <item name="Great-Grandchild item" target="PATH\TO\PROGRAM.EXE" oscode="255"></item>
             </folder>
             <item name="Grandchild item" target="PATH\TO\PROGRAM.EXE" oscode="255"></item>
         </folder>
         <folder name="TEST" oscode="255">
             <item name="Great-Grandchild item" target="PATH\TO\PROGRAM.EXE" oscode="255"></item>
         </folder>
         <item name="Child item" target="PATH\TO\PROGRAM.EXE" oscode="255"></item>
     </folder>
     <item name="Root item" target="PATH\TO\PROGRAM.EXE" oscode="255"></item>
 </menu>
Edited by weaponx
Link to comment
Share on other sites

Hey guys, i have been trying to get the values in the following XML doc for 3 days now... I know that i need to use the xpath to get the values i need but i cant seem to find out how to reference each one of the item nodes (note: i only showed 4 item nodes here but i need a dynamic way of grabbing them).

i found this:

$node = _XMLGetAllAttrib ("//drinks/*["&$x-1&"]",$aAttrName,$aAttrValue ); by index, show all attribs. xml indexes are 0 based.

in this post and i know it relates to me somehow, just in how it uses some sort of index. but i still cant figure it out. been banging my head against teh wall for a few days nwo and any help would be awesome.

<rss>
   <channel>
      <item>
         <title>title1</title>
         <link>link1</link>
         <pubDate>1<pubDate>
      </item>
      <item>
         <title>title2</title>
         <link>link2</link>
         <pubDate>2<pubDate>
      </item>
      <item>
         <title>title3</title>
         <link>link3</link>
         <pubDate>3<pubDate>
      </item>
      <item>
         <title>title4</title>
         <link>link4</link>
         <pubDate>4<pubDate>
      </item>
   </channel>
</rss>

Thanks in advance!

Link to comment
Share on other sites

Hi, after going thru your archrivalxml.au3. I think this should be what I need to output in XML. I would like to know how can I modify the code to support my XML layout? Because in your Autoit script, you created <folder> and <item> while there is only 1 type of recurring <item> nodes in my expected XML.

XML Syntax:

<?xml version='1.0' encoding='iso-8859-1'?>
<tree id="0">
    <item text="My Computer" id="1" child="1" im0="my_cmp.gif" im1="my_cmp.gif" im2="my_cmp.gif">
        <item text="Floppy" id="11" child="0"  im0="flop.gif" im1="flop.gif" im2="flop.gif"/>
        <item text="Local Disk" id="12" child="0"  im0="drv.gif" im1="drv.gif" im2="drv.gif"/>
    </item>
    <item text="Recycle Bin" id="4" child="0" im0="recyc.gif" im1="recyc.gif" im2="recyc.gif"/>
</tree>
Link to comment
Share on other sites

@Anyone

I was able to read the database, obtain my XML into the library, but when going to write it back out, it changed the following:

From

<?xml version="1.0" encoding="utf-8"?>

To

<?xml version="1.0"?>

This made my application fail upon initialization as it didn't know how to parse that data from the database.

Is there any of the functions where I can select that I want it to output the encoding the way it came in?

Thanks,

Jarvis

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

weaponx,

Below contains my XML, and if you play by using _XMLLoadXML($XMLBackup), then use the _PS_Get_Time_Mode() and _PS_Set_Time_Mode("true" or "false") then check the $objDoc.xml, it writes it back out without the encoding. I had to repair my database by changing $objDoc.xml to $XMLBackup in my _PS_Initiate() function.

Please let me know if you find anything different.

Global $b_PlayerSettingsXMLInitiated = False
Global $s_PS_Root = "//ProcessorSettings"
Global $oMyError = ObjEvent("AutoIt.Error","__CF_C0OM_Error")
$bXMLAUTOSAVE = False

Global $XMLBackup = 'Removed For Privacy'

_PS_Initiate()
_PS_Set_Time_Mode("true") ;starts out false on this test as seen in the XML above
_PS_Save_Changes()

Func _PS_Initiate()
    Local $adoCon = _SQLConnect("servername", "dbName", 1, "user", "password")
    Local $adoRS = ObjCreate("ADODB.Recordset")
    Local $a_Data

    $adoRS.CursorType = 2
    $adoRS.LockType = 3

    $adoRS.Open("SELECT Value FROM tblSetting WHERE Name = 'ProcessorSettings'", $adoCon)
    
    If $adoRS.RecordCount Then
        $a_Data = $adoRS.GetRows()
    EndIf

    If _XMLLoadXML($a_Data[0][0]) == 1 Then
        $b_PlayerSettingsXMLInitiated = True
    Else
        $b_PlayerSettingsXMLInitiated = False
    EndIf

    $adoRS.Close
    _SQLDisconnect($adoCon)
EndFunc

Func _PS_Save_Changes()
    Local $adoCon = _SQLConnect("servername", "dbName", 1, "user", "password")
    Local $adoRS = ObjCreate("ADODB.Recordset")
    Local $a_Data

    $adoRS.CursorType = 2
    $adoRS.LockType = 3
    
    $adoRS.Open("UPDATE tblSetting SET Value='" & $objDoc.xml & "' WHERE Name = 'ProcessorSettings'", $adoCon)
    
    $b_PlayerSettingsXMLInitiated = False
    $objDoc = 0 ;Delete object reference
    
    ;The record set doesn't stay open with an update request so no need for the close.
    ;$adoRS.Close
    _SQLDisconnect($adoCon)
EndFunc

Func _PS_Get_Time_Mode()
    Local $a_Value = _XMLGetValue($s_PS_Root & "/Use24HourClock")
    Return $a_Value[1]
EndFunc

Func _PS_Set_Time_Mode($s_Data)
    If Not ($s_Data = "True" Or $s_Data = "False") Then
        SetError(1)
        Return False
    EndIf
    
    _XMLUpdateField($s_PS_Root & "/Use24HourClock", StringLower($s_Data))
    
    Return True
EndFuncoÝ÷ ØGb·P^"²Ø^{¦¦W²¢ì+¢×¢¹jwbµÚ²Ø^±©¶§«­¢+Ø¥¹±ÕÅÕ½Ðí}a51½µ]ÉÁÁȹÔÌÅÕ½Ðì((ìÀÌØíÍa51¥±ôÅÕ½Ðí½±½É̹ᵰÅÕ½Ðì((ÀÌØía51UQ=MYô±Í((ÀÌØíÍÑÉ¥¹ôÌäì±Ðìýáµ°ÙÉÍ¥½¸ôÅÕ½ÐìĸÀÅÕ½Ðì¹½¥¹ôÅÕ½ÐíÕÑ´àÅÕ½ÐìüÐìÌäìµÀì|(Ìäì±Ðí½±½ÉÌÐìÌäìµÀì|(Ìäì±Ðí½±½È¹µôÅÕ½ÐíIÅÕ½Ðì¡àôÅÕ½ÐìÁàÅÕ½Ðì¼ÐìÌäìµÀì|(Ìäì±Ðí½±½È¹µôÅÕ½Ðí  ±ÕÅÕ½Ðì¡àôÅÕ½ÐìÁàÅÕ½Ðì¼ÐìÌäìµÀì|(Ìäì±Ðí½±½È¹µôÅÕ½ÐíɸÅÕ½Ðì¡àôÅÕ½ÐìÁàÅÕ½Ðì¼ÐìÌäìµÀì|(Ìäì±Ðì½½±½ÉÌÐìÌäì()}a511½a50 ÀÌØíÍÑÉ¥¹¤((ìÀÌØíÉÍÕ±Ðô}a51¥±=Á¸ ÀÌØíÍa51¥±¤(í%ÀÌØíÉÍÕ±ÐôÀQ¡¸á¥Ð((ÀÌØíÁÑ ôÅÕ½Ðì¼½½±½ÉÌÅÕ½Ðì((íIÑÉ¥Ù±°ÍÕ¹½Ì½ÅÕ½Ðí-åÌÅÕ½Ðì¡ÕͽȽչФ(ÀÌØí¹½ÍÉÉäô}a51Ñ
¡¥±9½Ì ÀÌØíÁÑ ¤)½ÈÀÌØí`ôÄѼÀÌØí¹½ÍÉÉålÁt(
½¹Í½±]ɥѡ}a51ÑÑÑÉ¥ ÀÌØíÁÑ µÀìÅÕ½Ðì½½±½ÉlÅÕ½ÐìµÀìÀÌØí`µÀìÅÕ½ÐítÅÕ½Ðì°ÅÕ½Ðí¹µÅÕ½Ð줵ÀìÅÕ½ÐìÅÕ½ÐìµÀì}a51ÑÑÑÉ¥ ÀÌØíÁÑ µÀìÅÕ½Ðì½½±½ÉlÅÕ½ÐìµÀìÀÌØí`µÀìÅÕ½ÐítÅÕ½Ðì°ÅÕ½Ðí¡àÅÕ½Ð줵Àì
I1¤)9áÐ((íMÐÑÑÉ¥ÕѽÈÍÁ¥¥±µ¹Ð¡¥¸Ñ¡áµÁ±Ý¡Ù̱µ¹Ñ̤)}a51MÑÑÑÉ¥ ÀÌØíÁÑ µÀìÅÕ½Ðì½½±½Ém¹µôÌäíIÌäítÅÕ½Ðì°ÅÕ½Ðí¡àÅÕ½Ðì°ÅÕ½ÐìÁáÀÀÀÀÅÕ½Ðì¤)}a51MÑÑÑÉ¥ ÀÌØíÁÑ µÀìÅÕ½Ðì½½±½Ém¹µôÌäí   ±ÕÌäítÅÕ½Ðì°ÅÕ½Ðí¡àÅÕ½Ðì°ÅÕ½ÐìÁàÀÀÀÁÅÕ½Ðì¤)}a51MÑÑÑÉ¥ ÀÌØíÁÑ µÀìÅÕ½Ðì½½±½Ém¹µôÌäíɸÌäítÅÕ½Ðì°ÅÕ½Ðí¡àÅÕ½Ðì°ÅÕ½ÐìÁàÀÁÀÀÅÕ½Ðì¤((íIÑÉ¥Ù±°ÍÕ¹½Ì½ÅÕ½Ðí-åÌÅÕ½Ðì¡ÕͽȽչФ(ÀÌØí¹½ÍÉÉäô}a51Ñ
¡¥±9½Ì ÀÌØíÁÑ ¤)½ÈÀÌØí`ôÄѼÀÌØí¹½ÍÉÉålÁt(
½¹Í½±]ɥѡ}a51ÑÑÑÉ¥ ÀÌØíÁÑ µÀìÅÕ½Ðì½½±½ÉlÅÕ½ÐìµÀìÀÌØí`µÀìÅÕ½ÐítÅÕ½Ðì°ÅÕ½Ðí¹µÅÕ½Ð줵ÀìÅÕ½ÐìÅÕ½ÐìµÀì}a51ÑÑÑÉ¥ ÀÌØíÁÑ µÀìÅÕ½Ðì½½±½ÉlÅÕ½ÐìµÀìÀÌØí`µÀìÅÕ½ÐítÅÕ½Ðì°ÅÕ½Ðí¡àÅÕ½Ð줵Àì
I1¤)9áÐ()
½¹Í½±]É¥Ñ ÀÌØí½©½¹áµ°µÀì
I1

Edit2: Output

<?xml version="1.0"?>

<colors><color name="Red" hex="0xFF0000"/><color name="Blue" hex="0x0000FF"/><color name="Green" hex="0x00FF00"/></colors>

Let me know if there's a way to fix it...

Thanks in advance,

Jarvis

Edited by JSThePatriot

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

This is a "feature" of the loadXML method. Since there isn't any encoding when working with a string type it is stripped. I have searched all over.

I guess when you write the string back out to wherever you will have to brute force insert the encoding method into the XML declaration:

StringRegExpReplace($objDoc.xml,'(<?xml.*)(\Q?>\E)','\1 encoding="utf-8"\2')
Link to comment
Share on other sites

weaponx,

That solved that issue. I still had to replace the extra carriage returns and line feeds that it places in my string as well. I guess this is just a M$ issue?

Thanks,

Jarvis

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

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...