Jump to content

Recommended Posts

Posted

Thanks.
I'm happy that some wants to do it.

mLipok

 

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

here is some new update description (not yet published) :

  Quote

    2015/10/xx
    "1.1.1.09"
    . Removed: Function: _XMLCreateChildNode - as it was duplicate feature with _XML_CreateChildWAttr - mLipok
    .        Thanks to: @scila1996
    .        https://www.autoitscript.com/forum/topic/176895-xmlwrapperexau3-beta/?do=findComment&comment=1278825
    . Removed: Function: _XMLCreateChildNodeWAttr - as it was only duplicate/wrapper for _XML_CreateChildWAttr - mLipok
    .        Thanks to: @scila1996
    .        https://www.autoitscript.com/forum/topic/176895-xmlwrapperexau3-beta/?do=findComment&comment=1278825

So just use _XML_CreateChildWAttr()

btw.

Working on update and new examples.

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 10/23/2015 at 10:25 PM, mLipok said:

here is some new update description (not yet published) :

So just use _XML_CreateChildWAttr()

btw.

Working on update and new examples.

 

:D i wish your script is up-to-date most early .

Posted
  On 10/23/2015 at 1:35 AM, scila1996 said:

You are check for _XML_GetNodeAttributeValue . It's not working and return 0 @error code 7

XML File

<?xml version="1.0" encoding="Windows-1258" standalone="no"?><Settings>
    <node0 type="menu0"/>
</Settings>

This code !

Local $oXMLDoc = _XML_CreateDOMDocument()
_XML_Load($oXMLDoc, "settings.xml")
MsgBox(64, "", _XML_NodeExists($oXMLDoc, "Settings/node0")) ; Return 1 ok
Local $onode = _XML_SelectNodes($oXMLDoc, "Settings/node0")
MsgBox(64, "", _XML_GetNodeAttributeValue($onode, "type") & @CRLF & "@Error Code :" & @error) ; return 0 | @error code = 7

 

I think you so modify the _XML_GetNodeAttributeValue into :)

Func _XML_GetNodeAttributeValue(ByRef $oXmlDoc, $sAttribute_Name)

 

You are using it wrong

 

you get @error = 7 == $XML_ERR_ISNOTVALIDNODES

Try this:

Local $oXMLDoc = _XML_CreateDOMDocument()
_XML_Load($oXMLDoc, "settings.xml")
MsgBox(64, "", _XML_NodeExists($oXMLDoc, "Settings/node0")) ; Return 1 ok
Local $oNode = _XML_SelectSingleNode($oXMLDoc, "Settings/node0")
MsgBox(64, "", _XML_GetNodeAttributeValue($oNode, "type") & @CRLF & "@Error Code :" & @error) ; return 0 | @error code = 7

As you can see this should work.

Focus on function name: _XML_GetNodeAttributeValue   this Function expect SingleNode not Nodes 
so you should use _XML_SelectSingleNode

I'm thinking about : about such a change $XML_ERR_ISNOTVALIDNODES >> $XML_ERR_ISNOTVALIDNODETYPE

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 10/24/2015 at 1:59 PM, mLipok said:

You are using it wrong

 

you get @error = 7 == $XML_ERR_ISNOTVALIDNODES

Try this:

Local $oXMLDoc = _XML_CreateDOMDocument()
_XML_Load($oXMLDoc, "settings.xml")
MsgBox(64, "", _XML_NodeExists($oXMLDoc, "Settings/node0")) ; Return 1 ok
Local $oNode = _XML_SelectSingleNode($oXMLDoc, "Settings/node0")
MsgBox(64, "", _XML_GetNodeAttributeValue($oNode, "type") & @CRLF & "@Error Code :" & @error) ; return 0 | @error code = 7

As you can see this should work.

Focus on function name: _XML_GetNodeAttributeValue   this Function expect SingleNode not Nodes 
so you should use _XML_SelectSingleNode

I'm thinking about : about such a change $XML_ERR_ISNOTVALIDNODES >> $XML_ERR_ISNOTVALIDNODETYPE

 

Yeah ! I'll try again . Thank you :D

Posted
  On 10/24/2015 at 2:44 AM, scila1996 said:

:D i wish your script is up-to-date most early .

In this case you should ask fequently, then progress will go on.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

I Think about some functions to do Read, Get, Check Value and without "Write or Method Impact to Object" . Example

 

Func __XML_IsValidObject_Attributes(ByRef $oAttributes)
Func __XML_IsValidObject_DOMDocument(ByRef $oXML)
Func __XML_IsValidObject_Node(ByRef $oNode, $iNodeType = Default)
Func __XML_IsValidObject_NodesColl(ByRef $oNodesColl)

Func _XML_GetNodeAttributeValue(ByRef $oNode_Selected, $sAttribute_Name)
Func _XML_SelectSingleNode(ByRef $oXmlDoc, $sXPath)

Change parameter to :

Func __XML_IsValidObject_Attributes(const $oAttributes)
Func __XML_IsValidObject_DOMDocument(const $oXML)
Func __XML_IsValidObject_Node(const $oNode, $iNodeType = Default)
Func __XML_IsValidObject_NodesColl(const $oNodesColl)

Func _XML_GetNodeAttributeValue(const $oNode_Selected, $sAttribute_Name)
Func _XML_SelectSingleNode(const $oXmlDoc, $sXPath)

 

Edited by scila1996
Posted
  On 10/23/2015 at 1:56 AM, scila1996 said:

Have a problem with _XML_DeleteNode

If delete one or more time it's to leave a "space line" at node just delete . Example :

<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?><Settings>
<node1/>
<node2/>
<node3/>
</Settings>

After delete "node1" and "node2" 

<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?><Settings>


<node3/>
</Settings>

Thereforce i was used _XML_TIDY to fix , but it's still to leave "space line" at that !

I'm thinking about adding this:

$sXML = StringRegExpReplace($sXML, '(?is)(\>)(\s*\R{2,}\s*)(\<)', '$1' & @CRLF & '$3')

to _XML_TIDY()

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 10/23/2015 at 1:44 AM, scila1996 said:

This function also not working

 

Local $oXMLDoc = _XML_CreateDOMDocument()
_XML_Load($oXMLDoc, "settings.xml")
Local $aAttr[0], $aVal[0]
MsgBox(64, "", _XMLGetAllAttrib($oXMLDoc, "Settings/Node0", $aAttr, $aVal) & @CRLF & "@Error Code " & @error) ; return 0 | @Error code = 22

XML File

<?xml version="1.0" encoding="Windows-1258" standalone="no"?><Settings>
    <node0 type="menu0" icon="shell32.dll" index="5"/>
</Settings>

 

"Settings/Node0"

is not the same as

"Settings/node0"

look here:

https://msdn.microsoft.com/en-us/library/ms757047(v=vs.85).aspx

  Quote

A string specifying the name for the new element node. The name is case-sensitive.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

Ah ! You can give me knows functions or method to create a Node Object . My Database is organized into Tree Structure , Inside a Node exists Like Nodes . ?

Example

<?xml version="1.0" encoding="UTF-8"?>
<SETTINGS>
    <test Test="1"/>
    <test Test="12"/>
    <test Test="123"/>
    <test Test="1234"/>
</SETTINGS>

How do i get all node "test" and get all attrib of each node ?

Thank you

Edited by scila1996
Posted

I wish new Script update will has a Function SwapNode by way using method .insertNode()

#include "_MSXML.au3"

Local $oXMLDoc
_MSXML_InitInstance($oXMLDoc)
_MSXML_FileOpen($oXMLDoc, "SettingsXML.xml")
Local $arr = _MSXML_SelectNodes($oXMLDoc, "Settings/node_test")
$arr[2].parentNode.insertBefore($arr[2], $arr[1])
$oXMLDoc.Save("SettingsXML.xml")

 

  • 4 weeks later...
Posted (edited)

Not checked but it should work.

EDIT: this was answer to "Is this udf working on v3.3.12.0 stable?"

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • 2 months later...
Posted

Did you try to use the second parameter ?
 

_XML_Tidy(ByRef $oXmlDoc, $sEncoding = Default)

or even:

_XML_MiscProperty_Encoding()

to setup charset ?

https://msdn.microsoft.com/en-us/library/ms681424(v=vs.85).aspx

For a list of the character set names that are known by a system, see the subkeys of HKEY_CLASSES_ROOT\MIME\Database\Charset in the Windows Registry.

 

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

I'm sorry if I wasn't clear, but I wanted _XML_Tidy to clean up only the indents and have no encoding or standalone attributes at all.  I guess I'm just asking if this is a feature that anyone else would appreciate and how to implement it if so.

  • 1 month later...
Posted (edited)
$time = "7" 
$comp = "101CHECKIN"
$service = "Sunday"
    
Func GetSettings()

    ; first you must create $oXmlDoc object
    Local $oXmlDoc = _XML_CreateDOMDocument(Default)
    If @error Then
        MsgBox(0, '_XML_CreateDOMDocument @error:', XML_My_ErrorParser(@error))
    Else
        ; now you can add EVENT Handler
        Local $oXMLDOM_EventsHandler = ObjEvent($oXmlDoc, "XML_DOM_EVENT_")
        #forceref $oXMLDOM_EventsHandler

        ; Load file to $oXmlDoc
        Local $sXmlFile = @ScriptDir & "\eSch1.xml"
        _XML_Load($oXmlDoc, $sXmlFile)
        If @error Then
            MsgBox(0, '_XML_Load @error:', XML_My_ErrorParser(@error))
        Else
            ; selecting nodes
            Local $allTimes = _XML_SelectNodes($oXmlDoc, "//Time")

                for $x = 1 to $allTimes.length

                    Local $currentTimeNode = _XML_SelectSingleNode($oXmlDoc, '//Time[' & $x & ']')
                    Local $hour = _XML_GetNodeAttributeValue($currentTimeNode, 'Hour')

                    If $time = $hour Then
                        MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, ' Correct Hour', $hour)
                        $setTimeNode = $currentTimeNode
                    EndIf

                Next

            Local $allDays = _XML_SelectNodes($oXmlDoc, "//Service")

                for $x = 1 to $allDays.length

                    Local $currentDayNode = _XML_SelectSingleNode($oXmlDoc, '//Service[' & $x & ']')
                    Local $day = _XML_GetNodeAttributeValue($currentDayNode, 'Day')

                    if $service = $day Then
                        MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, 'Correct Day', $day)
                        $setDayNode = $currentDayNode
                    EndIf

                Next

            Local $allComputers = _XML_SelectNodes($oXmlDoc, "//Computer")

                for $x = 1 to $allComputers.length

                    Local $currentComputerNode = _XML_SelectSingleNode($oXmlDoc, '//Computer[' & $x & ']')
                    Local $computer = _XML_GetNodeAttributeValue($currentComputerNode, 'Station')

                    If $comp = $computer Then
                        MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, 'Correct Computer', $computer)
                        $setComputerNode = $currentComputerNode
                    EndIf

                Next
;~~~~~~~~~~~~~~~~~~~~~~~~~ prety much lost from here on. How to use gathered information and return code and mode text~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
            Local $item = _XML_GetChildren($oXmlDoc, '//Checkin'  & $setDayNode & $setTimeNode &  $setComputerNode); we use the complete path to find the code and mode

                if @error Then
                    MsgBox(0, '_XML_Load @error:', XML_My_ErrorParser(@error))
                Else


                        MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, 'Example_1__XML_SelectNodes', $item)

                EndIf
        EndIf
    EndIf
EndFun

New to XML and still a noob in autoit and can't seam to figure this one out. I'm probably going about it all wrong but i'm not sure. I have a program I'm automating which is completed except for this last part which will find the settings needed.  Any help would be appreciated and if you can point me to some helpful information I'd love to understand myself.

I have a function where i pass 3 values, day, hour, and computer name. I need to get the Code, and Mode value form the XML to enter the correct settings in the application I've automated. I've attached the xml and test .au3 ive been working with I slimmed the test to just whats relevant. I have Several service days and different hours but stripped to just these for the sake of a short post.

 

Edit: Solved

Used the built in Microsoft XMLDOM object and it was pretty straight forward. This post

helped.

 

<Checkin>
    <Service Day="Sunday">
        <Time Hour="7">
        
            <Computer Station="101CHECKIN">
                <Code>7168</Code>
                <Mode>Assisted</Mode>
            </Computer>
            
            <Computer Station="211HALLCHECKIN">
                <Code>1668</Code>
                <Mode>Self</Mode>
            </Computer>
            
            <Computer Station="ACCESS01">
                <Code>4248</Code>
                <Mode>Assisted</Mode>
            </Computer>
        </Time>
    </Service>
</Checkin>

 

Edited by asdf1nit
Solved
  • 1 month later...
Posted (edited)

new version:

  Quote

2016/05/18
"1.1.1.10"

. NEW: Feature: _XML_Tidy:   if Parameter $sEncoding = -1 then .omitXMLDeclaration = true - mLipok
.            Feature asked by @GMK here:
.           https://www.autoitscript.com/forum/topic/176895-xmlau3-v-11109-formerly-xmlwrapperexau3-beta-support-topic/?do=findComment&comment=1294688
. Changed: _XML_Tidy(ByRef $oXmlDoc, $sEncoding = -1) - Default value is set to -1
. New:    XML__Example_TIDY.au3

2016/05/18
"1.1.1.09"

. !!!! UDF RENAMED XMLWrapperEx.au3 >> XML.au3 - mLipok
. Changed: Error Handling: all SetError($XML_ERR_NODEAPPEND, - returns @error as extended - as this is COM ERROR - mLipok
. Changed: Error Handling: all SetError($XML_ERR_NODECREATE, - returns @error as extended - as this is COM ERROR - mLipok
. Removed: Function: _XMLCreateChildNode - as it was duplicate feature with _XML_CreateChildWAttr - mLipok
.        Thanks to: @scila1996
.       https://www.autoitscript.com/forum/topic/176895-xmlwrapperexau3-beta/?do=findComment&comment=1278825
. Removed: Function: _XMLCreateChildNodeWAttr - as it was only duplicate/wrapper for _XML_CreateChildWAttr - mLipok
.        Thanks to: @scila1996
.       https://www.autoitscript.com/forum/topic/176895-xmlwrapperexau3-beta/?do=findComment&comment=1278825
. ! EXAMPLES FILE: Modified: XML_My_ErrorParser - mLipok
. ! EXAMPLES FILE: New: Example_2a__XML_CreateChildWAttr() - mLipok
. Removed: Enums: $XML_ERR_SAVEFILERO - New Requirment for saving - File Can Not Exist - user should manage it by their own - mLipok
. Renamed: Enums: $XML_ERR_ISNOTVALIDNODESE >> $XML_ERR_ISNOTVALIDNODETYPE - mLipok
. Renamed: Enums: $XML_ERR_ISNOTVALIDNODETYPE >> $XML_ERR_INVALIDNODETYPE - mLipok
. Renamed: Enums: $XML_ERR_ISNOTVALIDATTRIB >> $XML_ERR_INVALIDATTRIB - mLipok
. Renamed: Enums: $XML_ERR_ISNOTVALIDDOMDOC >> $XML_ERR_INVALIDDOMDOC - mLipok
. Removed: $XML_EXT_GENERAL >> $XML_EXT_DEFAULT - mLipok
. Changed: $XML_EXT_.. are reordered - mLipok
. Removed: Function: _XSL_GetDefaultStyleSheet - mLipok
.    This was example from:
.   http://www.xml.com/lpt/a/1681
.    But it is: Copyright © 1998-2006 O'Reilly Media, Inc.
. Renamed: Function: _XMLGetField >> _XML_GetField - mLipok
. Renamed: Function: _XMLGetValue >> _XML_GetValue - mLipok
. Renamed: Function: _XMLGetAllAttrib >> _XML_GetAllAttrib - mLipok
. Renamed: Function: _XMLSetAttrib >> _XML_SetAttrib - mLipok
. New: Function: _XML_InsertChildNode - GMK
. New: Function: _XML_InsertChildWAttr - GMK
. Changed: Function: _XML_CreateAttribute - numbers of parameters - mLipok
.            now you must pass an Array with AttributeName and AttributeValue
. Fixed: Function: _XMLCreateRootNode - GMK
.        $oXmlDoc.documentElement.appendChild($oChild) >> $oXmlDoc.appendChild($oChild)
. Fixed: Function: _XMLCreateRootNodeWAttr - GMK
.        $oXmlDoc.documentElement.appendChild($oChild_Node) >> $oXmlDoc.appendChild($oChild_Node)
. Renamed: Function: _XMLCreateRootChild >> _XML_CreateRootNode - GMK
.            !!!!!!!! @TODO need to be revisited
.
. Renamed: Function: _XMLCreateRootNodeWAttr >> _XML_CreateRootNodeWAttr - GMK
. ADDED: #CURRENT# - GMK
. ADDED: #IN_PROGESS# - GMK
. ADDED: #INTERNAL_USE_ONLY# - GMK
.         !!! Additional Thanks for GMK for testing and many changes in many Description
. CleanUp: Function: _XML_GetNodesPath - removed $sNodePathTag - mLipok - thanks to GMK
. CleanUp: Function: _XML_GetParentNodeName - removed $sNodePathTag - mLipok - thanks to GMK
. CleanUp: Function: removed #include <MsgBoxConstants.au3> - mLipok - thanks to GMK
. CleanUp: Function: _XML_GetField - removed $oChild - mLipok - thanks to GMK
. CleanUp: Function: _XML_GetNodesPath - MagicNumber 0 replaced with $STR_NOCASESENSE - mLipok - thanks to GMK
. CleanUp: Function: _XML_GetNodesPathInternal - MagicNumber 0 replaced with $STR_NOCASESENSE - mLipok - thanks to GMK
. CleanUp: Function: _XML_GetParentNodeName - MagicNumber 0 replaced with $STR_NOCASESENSE - mLipok - thanks to GMK
. Renamed: Function: _XMLCreateCDATA >> _XML_CreateCDATA - mLipok - thanks to GMK
. Rewrite: Function: _XML_GetAllAttrib - Parameters : removed ByRef $aName, ByRef $aValue - mLipok
. Fixed Typo: Descripton: Chceck >> Check - mLipok - thanks to GMK
. Added: Descripton: _XML_GetNodesCount - mLipok - thanks to GMK
. Changed: Descripton: _XML_TransformNode - mLipok - thanks to GMK
. Changed: Descripton: _XML_CreateDOMDocument - mLipok - thanks to GMK
. Added: Descripton: _XML_GetNodeAttributeValue - mLipok - thanks to GMK
. Changed: Descripton: _XML_Misc_Viewer - mLipok - thanks to GMK
. Changed: Function: _XML_SelectNodes in case of success @extended = $oNodesColl.length

Expand  

 

Download link:

 

 

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

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
×
×
  • Create New...