creating and appending nodes

Hi,

I am writing a function to create a new node in an existing data island and populating it with a user defined value. The following ciode, however, is giving me an error " Object required: mandNode" .Could someone help, please?

Code:
Function AppendNodes(nodeval,eleval,XMLDataIsl,Attr)

set doc=CreateObject("Microsoft.XMLDOM")
doc.async="false"
doc.load(XMLDataIsl.XML)

Set qtyelement = doc.createElement(eleval) ' qtyelement is the new node
Set qtytext = doc.createTextNode(nodeval) ' qtytext carries the value to be inserted into the new node

msgbox qtytext.nodevalue
qtyelement.appendChild(qtytext) 'appending

Set mandNode = doc.selectSingleNode("//mand[attribute='" & Trim(Attr) & "']") 'refer the data island attached

mandNode.appendChild qtyelement

End Function
______________________
Data Island:
<XML id="AttrDisp">

<root>
<header>

<headerinfo>

<attribute> BOM </attribute>
<attrtype>number</attrtype>
<attrno> 4</attrno>
</headerinfo>
:
:
:

</header>

<mandheader>

<mand>
<PCB>23</PCB>
<attribute> BOM </attribute>
<attrtype>number</attrtype>
<attrno> 4</attrno>
</mand>

<mand>
<PCB>23</PCB>
<attribute> PCB_Size </attribute>
<attrtype>text</attrtype>
<attrno> 5</attrno>
</mand>

<mand>
<PCB>23</PCB>
<attribute> Date_Issued </attribute>
<attrtype>date</attrtype>
<attrno> 6</attrno>
</mand>

<mand>
<PCB>23</PCB>
<attribute> Proto_Run_Lot </attribute>
<attrtype>number</attrtype>
<attrno> 7</attrno>
</mand>

<mand>
<PCB>23</PCB>
<attribute> PCB_PN </attribute>
<attrtype>text</attrtype>
<attrno> 0</attrno>
</mand>

<mand>
<PCB>23</PCB>
<attribute> Module_PN </attribute>
<attrtype>text</attrtype>
<attrno> 1</attrno>
</mand>

<mand>
<PCB>23</PCB>
<attribute> Panel_Size </attribute>
<attrtype>text</attrtype>
<attrno> 2</attrno>
</mand>

<mand>
<PCB>23</PCB>
<attribute> PCB_Panel </attribute>
<attrtype>text</attrtype>
<attrno> 3</attrno>
</mand>

</mandheader>
</root>
</XML>
[3102 byte] By [erin] at [2007-11-18 18:59:35]