Recommended Posts

ModemJunki 4

ModemJunki 4

Using the XML wrapper in the link above (also attached here), how can I enumerate the names within a section in the XML file?

Lets say I want to extract all of the setting names inside the below XML, I try using the function _XMLGetAllAttrib but there is no result. I was expecting that $a_names would contain the attribute names.

Share this post

Link to post

Share on other sites

AdamUL 67

AdamUL 67

Your welcome, glad I could help. I believe this function has some issues.

This UDF needs a lot of updating, at least to me. i am currently working on project that deals with a lot of XML files. To make my work easier, I'm currently working on updating this UDF to make it possible to work with multiple XML files at the same time. I'm also working on determining how the functions work, if they do what they say they will do, and determine if some are even needed. For some things, it is easier to work with the DOM's properties and methods directly. I plan on adding the updated UDF library to Example Scripts, when I finish updating it.

Sign in

Similar Content

This XML things are driving me crazy...
Please let me know how can I use the _XMLGetAttrib function... I've tried every possible way that I've read on the forum and I cannot succeed reading an attribute.

Can anyone assist with creating/modify/delete XML Nodes/Child Nodes?
Have a document for example:
<ConfigData>
<parameter>
<name>Setting One</name>
<value>10</value>
</parameter>
<parameter>
<name>IPAddress</name>
<value>192.168.1.1</value>
</parameter>
<parameter>
<name>Setting One</name>
<value>200</value>
</parameter>
<parameter>
<name>Setting Three</name>
<value>300</value>
</parameter>
</ConfigData>
Would like to add another node parameter/name, parameter/value, but unsure how to, when there are multiple instances with the same tagname for example, would like to add the following if the nodes do not already exist:
<parameter>
<name>UserPreferredLanguage</name>
<value>English</value>
</parameter>
Currently using the following to check and delete/modify existing nodes, was thinking of placing the name and value into a 2d array and then using a true/false in a 3rd column to return if the setting was found and modified or not, so I can decide whether I need to create the nodes or not, but I'm hoping there is a simpler way.\
Any assistance would be much appreciated.
PS: Have also written this with the XML Dom Wrapper UDF but still unsure how to proceed with checking nodes and creating them if they're missing, also couldn't find a function to delete a full node + parent using selectNodes, hence the custom __XML_DeleteNode function.
Thanks
Local $sXMLDocPath = @ScriptDir & "\XMLDoc.xml"
Local $oXMLDoc = ObjCreate("MSXML2.DOMDocument")
$oXMLDoc.validateOnParse = False
$oXMLDoc.load($sXMLDocPath)
Local $oXMLNodes = $oXMLDoc.selectNodes("ConfigData/parameter")
If IsObj($oXMLNodes) Then
For $oXMLNode In $oXMLNodes
If $oXMLNode.childNodes.item(0).tagName = "Name" And $oXMLNode.childNodes.item(0).Text = "Setting One" Then
If $oXMLNode.childNodes.item(1).tagName = "Value" Then $oXMLNode.childNodes.item(1).Text = 10
EndIf
If $oXMLNode.childNodes.item(0).tagName = "Name" And $oXMLNode.childNodes.item(0).Text = "IPAddress" Then
__XML_DeleteNode($oXMLNode)
EndIf
If $oXMLNode.childNodes.item(0).tagName = "Name" And $oXMLNode.childNodes.item(0).Text = "Setting Two" Then
If $oXMLNode.childNodes.item(1).tagName = "Value" Then $oXMLNode.childNodes.item(1).Text = 20
EndIf
If $oXMLNode.childNodes.item(0).tagName = "Name" And $oXMLNode.childNodes.item(0).Text = "Setting Three" Then
If $oXMLNode.childNodes.item(1).tagName = "Value" Then $oXMLNode.childNodes.item(1).Text = 30
EndIf
Next
EndIf
$oXMLDoc.Save ($sXMLDocPath)
Func __XML_DeleteNode($_oNode_Enum)
If $_oNode_Enum.hasChildNodes Then
For $_oNode_Enum_Child In $_oNode_Enum.childNodes
If $_oNode_Enum_Child.nodeType = $XML_NODE_TEXT Then
If StringStripWS($_oNode_Enum_Child.text, $STR_STRIPLEADING + $STR_STRIPTRAILING + $STR_STRIPSPACES) = "" Then
$_oNode_Enum.removeChild($_oNode_Enum_Child)
EndIf
EndIf
Next
EndIf
$_oNode_Enum.parentNode.removeChild($_oNode_Enum)
EndFunc

Hello,
following my previous question, I have moved all potentially instable object interactions into Executes. But it Looks like "="-assignments to object Attributes cannot be done with Execute, only method calls. Using an "$obj = 1" construct, it compares (Eval) instead of sets (Execute) the value.
I have tested multiple different combinations, using Execute and Assign, but it seems not to work with object Attributes. :-(
Gives following Output:
The assign Action using apply (a3) Fails, while assigning it directly, without Assign() works fine.
The execute versions compare and do not assign, in both cases. Though, the "Execute" topic in the help file says it executes, not evaluates.
I have found a similar, old thread, which explains this behavious but does not give a solution. https://www.autoitscript.com/forum/topic/110228-pass-object-property-as-a-variable/
Is there a way to assign to a com object's Attribute? Or is there anything new to this unexpected behaviour of Execute (at least compared to the help file description and Python's exec).

Any help is appreciated, and thank you for all the help so far.
Regards, Michael