Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xml insertbefore method 1

Status
Not open for further replies.

lazytrucker

Programmer
Aug 4, 2004
39
GB
Whilst tying to insert a node before a certain element I keep getting a parentheses error:

Cannot use parentheses when calling a Sub
xmldoc.documentelement.insertBefore(Journey,xmldoc.documentelement.childnodes.item(i).childnodes.item(1))

I Have tried several methods:

1:

set Journey=xmldoc.createelement("Journey")
Journey.text= "Blank_For_Loop_Purposes"
xmldoc.documentelement.childnodes.item(i).childnodes.item(1).appendchild(Journey)
xmldoc.documentelement.insertBefore(Journey,xmldoc.documentelement.childnodes.item(i).childnodes.item(1))

2:

var new_node = xml_doc.createElement("Journey")
var new_text = xml_doc.createTextNode("Blank_For_Loop_Purposes")
new_node.appendChild(new_text)
'var root = xml_doc.documentElement
root.insertBefore(new_node, root.childnodes.item(i).childnodes.item(1))

All result in the same error mentioned above anyone got any ideas??

Cheers LazyTrucker.
 
Ok I have found that if you put CALL in front of the insertbefore line the error does not occur however niether does the new node.

Any other Ideas anyone???????
 
When you execute a sub (sub's do not return a value) you aren't supposed to use parans around the arguments (likewise with a function if you don't plan on using the return value).

All you have to do to correct those is:
1)
xmldoc.documentelement.childnodes.item(i).childnodes.item(1).appendchild Journey
xmldoc.documentelement.insertBefore Journey,xmldoc.documentelement.childnodes.item(i).childnodes.item(1)

2)
root.insertBefore new_node, root.childnodes.item(i).childnodes.item(1)

This is some VB thing that is irregularly enforced for ASP (or I just don't notice it anymore). Basic rule of thumb is tat you don't use parans with sub's and (probably) don't use parans with functions if your not capturing the return value (though I don't think it matters with functions).

Sorry about the lack of definitive anwer on functions with parans, this falls under one of those things I do without thinking, and now that I'm thinking about it I don't know what I do :p Kinda like my ATM card number, I thought about it to hard the other day and it took me three days to remember it again :)

-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
Need an expensive ASP developer in the North Carolina area? Feel free to let me know.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top