Jump to content

How to create a special format attribute in XML file


bhumis
 Share

Recommended Posts

I am still new to AutoIT. I have included _XMLDomWrapper.au3 in my script and tried using _XMLCreateAttrib and _XMLCreateChildWAttr methods.

I need to add the below attribute into the XML file after the "ip" attribute.

Attribute:

<displayFieldUUID name="task">A23ET45</displayFieldUUID>

XML File:

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

- <configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="mapping_schema.xsd">

<version>1.0</version>

<publisher name="ABCD" />

<action>EXPORT_FROM_A</action>

- <application CRUDOptions="IGNORE" name="Application">

<applicationUUID>2F57FE87</applicationUUID>

- <searchField>

<displayFieldUUID name="ip">B405EFDB</displayFieldUUID>

<displayFieldUUID name="criticality">E94E9D77</displayFieldUUID>

</searchField>

</application>

</configuration>

I tried the following method but it gives error.

$strAttribName = "task"

$strAttribValue = "A23ET45"

_XMLCreateAttrib("//configuration/application/searchField/displayFieldUUID", $strAttribName, $strAttribValue)

-bhumis

Link to comment
Share on other sites

Here is an example:

$string = '<XML><Group name="Office1"><host><name>O1Pc1</name><ip>192.168.0.1</ip></host><host><name>O1Pc2</name><ip>192.168.0.2</ip></host></Group><Group name="Office2"><host><name>O2Pc1</name><ip>192.168.0.11</ip></host><host><name>O2Pc2</name><ip>192.168.0.12</ip></host></Group></XML>'
$oXML=ObjCreate("Microsoft.XMLDOM")
;$XML = @DesktopDir & "xml1.xml"
;$oXML.load($XML) ; load document
$oXML.loadxml($string) ; load document
ConsoleWrite ( $oXML.xml & @CRLF)
$iCounter = 1
$result = $oXML.selectNodes( '//Group' )

$oXML.createAttribute("something")
For $oNode In $result
$oNode.setattribute ("something", 'test' & $iCounter)
$iCounter += 1
Next
ConsoleWrite ( $oXML.xml & @CRLF)

That creates an attribute, which you may then associate to a node object (cannot use xpath with .setattribute)

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
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...