Jump to content

Recommended Posts

Posted (edited)

Someone please help.

I am trying to insert a new node before a certain node, but I get an error, Variable must be of type "Object".:

Code is:

Local $oXML = ObjCreate("Microsoft.XMLDOM")

Local $oResult

    $oXML.load("C:\Utilities\Temp\report.hr5")

        Local $oEmail=$oXML.SelectSingleNode("//ClientData/prop[@name='CEmail']")
        $oOther=$oXML.SelectSingleNode("//ClientData/prop[@name='CFName1']")
        $Client1Fname=$oOther.text
        Local $oNode = $oXML.SelectSingleNode("//ClientData")
        Local $oNew = $oXML.CreateElement("Prop")
        Local $oName = $oXML.createAttribute("name")
        $oName.value = "CLName1"                
        Local $oType = $oXML.createAttribute("type")
        $oType.value = "0"
        ;$oNode.AppendChild($oNew)              ;Append works if I un comment this line and comment out the following line
        $oResult.InsertBefore($oNew,$oEmail)    ;This is where it fails
With $oNode.lastChild
  .attributes.setNamedItem($oName)
  .attributes.setNamedItem($oType)
  .text = $Client1Fname
EndWith


    $oxml.save("C:\Utilities\Temp\report.hr5")

Thanks for your assistance

report.hr5

Edited by AutoitMike
Link to post
Share on other sites

OK,

I figured it out.

;If using "Append" use the following:
With $oNode.lastChild
  .attributes.setNamedItem($oName)
  .attributes.setNamedItem($oType)
  .text = $Client1Fname
EndWith

;If using "Insert" use the following:
With $oNew
  .attributes.setNamedItem($oName)
  .attributes.setNamedItem($oType)
  .text = $Client1Fname
EndWith

 

Link to post
Share on other sites

Alternative

Local $oXML = ObjCreate("Microsoft.XMLDOM")
    $oXML.load("C:\Utilities\Temp\report.hr5")
Local $oEmail=$oXML.SelectSingleNode("//ClientData/prop[@name='CEmail']")
Local $oOther=$oXML.SelectSingleNode("//ClientData/prop[@name='CFName1']")
    $Client1Fname=$oOther.text
Local $oNode = $oXML.SelectSingleNode("//ClientData")
Local $oNew = $oXML.CreateElement("Prop")
    $oNew.setAttribute("name", "CLName1")
    $oNew.setAttribute("type", "0")
    $oNew.text = $Client1Fname
;~ Insert new node
    $oNode.InsertBefore($oNew,$oEmail)
;~ Append new node
;~  $oNode.AppendChild($oNew)

$oxml.save("C:\Utilities\Temp\report.hr5")

 

Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...