Jump to content

Recommended Posts

Posted (edited)

I am trying to create and append a node that reads like the following:

prop name="xxx" type="0"

This is what it looks like when using XML viewer.

When using notepad (to just view it) it looks like this:

<prop name="xxx" type="0">xxx value</prop>

For nodes with ordinary names, I have no problem adding nodes, EG:

$oOther = $oXML.SelectSingleNode('//xCity')
    $Node=$oXML.CreateElement('ABC')
    $oOther.AppendChild($Node)

The above works fine.

In another program I have no problem  reading , selecting and setting these types of nodes, EG:

$oOther = $oXML.SelectSingleNode("//xInfo/prop[@name='zzz']")
    MsgBox(0,"",$oOther.text)
    $oOther.text="123"

Thanks for any help

Edited by AutoitMike
Posted (edited)

This is what you are looking for, I believe :

Local $oNode = $oXML.SelectSingleNode("//Something[@id='1']") ; <<<<<<<<  modify accordingly
Local $oNew = $oXML.CreateElement("Prop")
Local $oName = $oXML.createAttribute("name")
$oName.value = "ABC"
Local $oType = $oXML.createAttribute("type")
$oType.value = "0"
$oNode.AppendChild($oNew)
With $oNode.lastChild
  .attributes.setNamedItem($oName)
  .attributes.setNamedItem($oType)
  .text = "123"
  ConsoleWrite("add new tag : " & .xml & @CRLF)
EndWith

 

Edited by Nine
typo
Posted (edited)

Thanks Nine,

I may have miss led you on one item.

The parent node is plain, EG:

"//ClientList"

Then, I need to add the child "Prop name='xxx' type="0"

Thanks again

Edited by AutoitMike
Clarify
Posted

Nine,

I get an error "The requested action with this object has failed."  on the line that attempts to appendChild(New)

I changed the first line to:

Local $oNode = $oXML.SelectSingleNode("//ClientList")

This is the parent node

Thanks

Posted
Posted

Thanks for the link.

The documentation is quite overwhelming.

Why would an application use this screwy method of defining node names?

//ABC/MyNode works pretty well.

Is there a specific advantage for “prop name”=“Abc” type=“0” ??

Posted

junkew,

Then the node specification "prop[@name='element name'] " is how to reference a node that has an attribute/s.

whereas 

"//Root/node name" is how you reference a node that has no attributes???

 

 

 

 

 

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