Jump to content
Sign in to follow this  
the123punch

_XMLDomWrapper help with creating nodes

Recommended Posts

the123punch

Hello all,

I am trying to write to an XML file that is already created. Basically I need to update it when there is new data coming in. I have an AutoIt script that is supposed to do this and I am using _XMLDomWrapper UDF for all my XML handling.

This is the structure of my XML file.

CODE
<?xml version="1.0" encoding="windows-1252"?>

<list next="569" timestamp="4036" schemastamp="23">

<Schema next="15">

<ElementType name="item">

<element id="s1" type="id" display="No"/>

<!-- must have an id on every row -->

<element id="s2" type="Nom" display="Yes" values=""/>

<element id="s3" type="Prénom" display="Yes" values=""/>

<element id="s4" type="Ext1" display="Yes" values=""/>

<element id="s5" type="Ext2" display="Yes" values=""/>

<element id="s6" type="Notes" display="Yes" values=""/>

<element id="s7" type="Dept" display="Yes" values=""/>

<element id="s8" type="Dept2" display="No" values=""/>

<element id="s9" type="Keyword" display="No" values=""/>

<element id="s10" type="temp" display="No" values=""/>

<element id="s11" type="LoginName" display="Yes" values=""/>

<element id="s12" type="Experties" display="Never" values=""/>

<element id="s13" type="Admin" display="No" values="Yes,No"/>

</ElementType>

</Schema>

<item>

<id>1</id>

<Nom>Forgi</Nom>

<Prénom>Pat</Prénom>

<Ext1>43473</Ext1>

<Ext2>

</Ext2>

<Notes/>

<Dept>TI</Dept>

<Dept2>IT</Dept2>

<Keyword>PForg</Keyword>

<temp>

</temp>

<LoginName>pforg</LoginName>

<Experties>Database,MDL,Oracle</Experties>

<Experties/>

<Admin/>

</item>

<item>

<id>3</id>

<Nom>Mamadde</Nom>

<Prénom>Dan Dr</Prénom>

<Ext1>4327</Ext1>

<Ext2>

</Ext2>

<Notes/>

<Dept>Sciences Biologiques</Dept>

<Dept2>Biological Sciences</Dept2>

<Keyword>Mamadde</Keyword>

<Experties/>

<LoginName>danmam</LoginName>

<Admin/>

</item>

</list>

So I basically need to add the node <item> and its child nodes everytime I am creating a new user and appending it to this XML file.

I tried using the function _XMLCreateChildNode("/list", "item", "id") with these parameters but it gave me the following results on the XML file which is not what I want.

<item>id</item>

Instead what I would need to get to add on the XML file would be the following:

<item>

<id>4</id>

<Nom>Hollister</Nom>

<Prénom>John</Prénom>

<Ext1>4354</Ext1>

<Ext2></Ext2>

<Notes/>

<Dept>Chemistry</Dept>

<Dept2>Chemistry</Dept2>

<Keyword>JHollister</Keyword>

<Experties/>

<LoginName>jhollister</LoginName>

<Admin/>

</item>

How can I go about and do that with the _XMLDomWrapper UDF??? I would try to do that with the _XMLCreateChildNode() function but I don't know how to actually write all the child nodes with their respective values.

Can someone please help me out with this?

Thanks.

the123punch

Share this post


Link to post
Share on other sites
the123punch

BUMP!.

Does anyone know how I would go about to do that please?

Thanks.

the123punch

Share this post


Link to post
Share on other sites
PsaltyDS

Hello all,

I am trying to write to an XML file that is already created. Basically I need to update it when there is new data coming in. I have an AutoIt script that is supposed to do this and I am using _XMLDomWrapper UDF for all my XML handling.

This is the structure of my XML file.

CODE
<?xml version="1.0" encoding="windows-1252"?>

<list next="569" timestamp="4036" schemastamp="23">

<Schema next="15">

<ElementType name="item">

<element id="s1" type="id" display="No"/>

<!-- must have an id on every row -->

<element id="s2" type="Nom" display="Yes" values=""/>

<element id="s3" type="Prénom" display="Yes" values=""/>

<element id="s4" type="Ext1" display="Yes" values=""/>

<element id="s5" type="Ext2" display="Yes" values=""/>

<element id="s6" type="Notes" display="Yes" values=""/>

<element id="s7" type="Dept" display="Yes" values=""/>

<element id="s8" type="Dept2" display="No" values=""/>

<element id="s9" type="Keyword" display="No" values=""/>

<element id="s10" type="temp" display="No" values=""/>

<element id="s11" type="LoginName" display="Yes" values=""/>

<element id="s12" type="Experties" display="Never" values=""/>

<element id="s13" type="Admin" display="No" values="Yes,No"/>

</ElementType>

</Schema>

<item>

<id>1</id>

<Nom>Forgi</Nom>

<Prénom>Pat</Prénom>

<Ext1>43473</Ext1>

<Ext2>

</Ext2>

<Notes/>

<Dept>TI</Dept>

<Dept2>IT</Dept2>

<Keyword>PForg</Keyword>

<temp>

</temp>

<LoginName>pforg</LoginName>

<Experties>Database,MDL,Oracle</Experties>

<Experties/>

<Admin/>

</item>

<item>

<id>3</id>

<Nom>Mamadde</Nom>

<Prénom>Dan Dr</Prénom>

<Ext1>4327</Ext1>

<Ext2>

</Ext2>

<Notes/>

<Dept>Sciences Biologiques</Dept>

<Dept2>Biological Sciences</Dept2>

<Keyword>Mamadde</Keyword>

<Experties/>

<LoginName>danmam</LoginName>

<Admin/>

</item>

</list>

So I basically need to add the node <item> and its child nodes everytime I am creating a new user and appending it to this XML file.

I tried using the function _XMLCreateChildNode("/list", "item", "id") with these parameters but it gave me the following results on the XML file which is not what I want.

<item>id</item>

Instead what I would need to get to add on the XML file would be the following:

<item>

<id>4</id>

<Nom>Hollister</Nom>

<Prénom>John</Prénom>

<Ext1>4354</Ext1>

<Ext2></Ext2>

<Notes/>

<Dept>Chemistry</Dept>

<Dept2>Chemistry</Dept2>

<Keyword>JHollister</Keyword>

<Experties/>

<LoginName>jhollister</LoginName>

<Admin/>

</item>

How can I go about and do that with the _XMLDomWrapper UDF??? I would try to do that with the _XMLCreateChildNode() function but I don't know how to actually write all the child nodes with their respective values.

Can someone please help me out with this?

Thanks.

the123punch

Try this:
#include <_XMLDomWrapper.au3>

Global $sXML = @ScriptDir & "\Test_1.xml"
Global $RET

; Open existing XML file
$RET = _XMLFileOpen($sXML)
If @error Or $RET <> 1 Then
    MsgBox(16, "Error", "Failed to open file: " & $sXML)
    Exit
EndIf

; Add new entry
$RET = _AddMyXmlItem(4, "Hollister", "John", "4354", "", "", "Chemistry", "Chemistry", "JHollister", "", "jhollister", "")
If @error Then
    MsgBox(16, "Error", "Failed to add item.")
Else
    MsgBox(64, "Success", "Added item successfully." & @CRLF & _
            "There are now " & $RET & " 'item' nodes.")
EndIf


; Function to add new users
Func _AddMyXmlItem($iID, $sNom, $sPrenom, $sExt1, $sExt2, $sNotes, $sDept, $sDept2, $sKeyword, $sExperties, $sLoginName, $sAdmin)
; Add the new 'item' node
    _XMLCreateChildNode("/list", "item")
    If @error Then Return SetError(1, 0, 0)
    
; Find out how many 'item' nodes there are now
    Local $iItemCount = _XMLGetNodeCount("/list/item")
    
; Add the child nodes under the new item
    Local $iError = 0
    _XMLCreateChildNode("/list/item[" & $iItemCount & "]", "id", String($iID))
    $iError += @error
    _XMLCreateChildNode("/list/item[" & $iItemCount & "]", "Nom", String($sNom))
    $iError += @error
    _XMLCreateChildNode("/list/item[" & $iItemCount & "]", "Prénom", String($sPrenom))
    $iError += @error
    _XMLCreateChildNode("/list/item[" & $iItemCount & "]", "Ext1", String($sExt1))
    $iError += @error
    _XMLCreateChildNode("/list/item[" & $iItemCount & "]", "Ext2", String($sExt2))
    $iError += @error
    _XMLCreateChildNode("/list/item[" & $iItemCount & "]", "Notes", String($sNotes))
    $iError += @error
    _XMLCreateChildNode("/list/item[" & $iItemCount & "]", "Dept", String($sDept))
    $iError += @error
    _XMLCreateChildNode("/list/item[" & $iItemCount & "]", "Dept2", String($sDept2))
    $iError += @error
    _XMLCreateChildNode("/list/item[" & $iItemCount & "]", "Keyword", String($sKeyword))
    $iError += @error
    _XMLCreateChildNode("/list/item[" & $iItemCount & "]", "Experties", String($sExperties))
    $iError += @error
    _XMLCreateChildNode("/list/item[" & $iItemCount & "]", "LoginName", String($sLoginName))
    $iError += @error
    _XMLCreateChildNode("/list/item[" & $iItemCount & "]", "Admin", String($sAdmin))
    $iError += @error
    
    
; Return results
    If $iError Then
; Error adding property nodes, return = 0, @error = 2, @extended = failed count
        Return SetError(2, $iError, 0)
    Else
; No errors, return new 'item' count
        Return $iItemCount
    EndIf
EndFunc ;==>_AddMyXmlItem

:P

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


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
Sign in to follow this  

×