473,386 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

XML and ASP

How can I add a child node to XML node "ItemID" below?
Thanks for assistance.

Dim oDOM : Set oDOM = Server.CreateObject("MSXML2.DOMDocument.3.0")
oDOM.LoadXML "<rss version=""2.0""></rss>"
AddElem oDOM.documentElement, "ItemID", "15314"

Function AddElem(roParent, rsName, rvntValue)
Set AddElem = roParent.ownerDocument.createElement(rsName)
roParent.appendChild AddElem
If Not IsNull(rvntValue) AddElem.Text = rvntValue
End Function

Jun 12 '07 #1
11 2645

<vu******@gmail.comwrote in message
news:11**********************@n15g2000prd.googlegr oups.com...
How can I add a child node to XML node "ItemID" below?
Thanks for assistance.

Dim oDOM : Set oDOM = Server.CreateObject("MSXML2.DOMDocument.3.0")
oDOM.LoadXML "<rss version=""2.0""></rss>"
AddElem oDOM.documentElement, "ItemID", "15314"

Function AddElem(roParent, rsName, rvntValue)
Set AddElem = roParent.ownerDocument.createElement(rsName)
roParent.appendChild AddElem
If Not IsNull(rvntValue) AddElem.Text = rvntValue
End Function
Dim oItem

Set oItem = AddElem(oDOM.documentElement, "ItemID", "15314")
AddElem oItem, "subID", "AB"

This would create the XML:-

<rss version="2.0">
<ItemID>15314<subID>AB</subID></itemID>
</rss>

Jun 12 '07 #2
On Jun 12, 3:26 am, "Anthony Jones" <A...@yadayadayada.comwrote:
<vunet...@gmail.comwrote in message

news:11**********************@n15g2000prd.googlegr oups.com...
How can I add a child node to XML node "ItemID" below?
Thanks for assistance.
Dim oDOM : Set oDOM = Server.CreateObject("MSXML2.DOMDocument.3.0")
oDOM.LoadXML "<rss version=""2.0""></rss>"
AddElem oDOM.documentElement, "ItemID", "15314"
Function AddElem(roParent, rsName, rvntValue)
Set AddElem = roParent.ownerDocument.createElement(rsName)
roParent.appendChild AddElem
If Not IsNull(rvntValue) AddElem.Text = rvntValue
End Function

Dim oItem

Set oItem = AddElem(oDOM.documentElement, "ItemID", "15314")
AddElem oItem, "subID", "AB"

This would create the XML:-

<rss version="2.0">
<ItemID>15314<subID>AB</subID></itemID>
</rss>
thank you. but how to append new child to subID?

Jun 14 '07 #3

<vu******@gmail.comwrote in message
news:11**********************@e9g2000prf.googlegro ups.com...
On Jun 12, 3:26 am, "Anthony Jones" <A...@yadayadayada.comwrote:
<vunet...@gmail.comwrote in message

news:11**********************@n15g2000prd.googlegr oups.com...
How can I add a child node to XML node "ItemID" below?
Thanks for assistance.
Dim oDOM : Set oDOM = Server.CreateObject("MSXML2.DOMDocument.3.0")
oDOM.LoadXML "<rss version=""2.0""></rss>"
AddElem oDOM.documentElement, "ItemID", "15314"
Function AddElem(roParent, rsName, rvntValue)
Set AddElem = roParent.ownerDocument.createElement(rsName)
roParent.appendChild AddElem
If Not IsNull(rvntValue) AddElem.Text = rvntValue
End Function
Dim oItem

Set oItem = AddElem(oDOM.documentElement, "ItemID", "15314")
AddElem oItem, "subID", "AB"

This would create the XML:-

<rss version="2.0">
<ItemID>15314<subID>AB</subID></itemID>
</rss>

thank you. but how to append new child to subID?
Dim oItem, oSubItem

Set oItem = AddElem(oDOM.documentElement, "ItemID", "15314")
Set oSubItem = AddElem(oItem, "subID", Null)
AddElem oSubItem, "subsub", "Stuff"

Creates:-

<rss version="2.0">
<ItemID>15314<subID><subsub>Stuff</subsub></subID></itemID>
</rss>


Jun 14 '07 #4
On Jun 14, 8:28 am, "Anthony Jones" <A...@yadayadayada.comwrote:
<vunet...@gmail.comwrote in message

news:11**********************@e9g2000prf.googlegro ups.com...
On Jun 12, 3:26 am, "Anthony Jones" <A...@yadayadayada.comwrote:
<vunet...@gmail.comwrote in message
>news:11**********************@n15g2000prd.googleg roups.com...
How can I add a child node to XML node "ItemID" below?
Thanks for assistance.
Dim oDOM : Set oDOM = Server.CreateObject("MSXML2.DOMDocument.3.0")
oDOM.LoadXML "<rss version=""2.0""></rss>"
AddElem oDOM.documentElement, "ItemID", "15314"
Function AddElem(roParent, rsName, rvntValue)
Set AddElem = roParent.ownerDocument.createElement(rsName)
roParent.appendChild AddElem
If Not IsNull(rvntValue) AddElem.Text = rvntValue
End Function
Dim oItem
Set oItem = AddElem(oDOM.documentElement, "ItemID", "15314")
AddElem oItem, "subID", "AB"
This would create the XML:-
<rss version="2.0">
<ItemID>15314<subID>AB</subID></itemID>
</rss>
thank you. but how to append new child to subID?

Dim oItem, oSubItem

Set oItem = AddElem(oDOM.documentElement, "ItemID", "15314")
Set oSubItem = AddElem(oItem, "subID", Null)
AddElem oSubItem, "subsub", "Stuff"

Creates:-

<rss version="2.0">
<ItemID>15314<subID><subsub>Stuff</subsub></subID></itemID>
</rss>
Sorry for asking more, but... how can I add an attribute?

Jun 15 '07 #5

<vu******@gmail.comwrote in message
news:11*********************@m36g2000hse.googlegro ups.com...
On Jun 14, 8:28 am, "Anthony Jones" <A...@yadayadayada.comwrote:
<vunet...@gmail.comwrote in message

news:11**********************@e9g2000prf.googlegro ups.com...
On Jun 12, 3:26 am, "Anthony Jones" <A...@yadayadayada.comwrote:
<vunet...@gmail.comwrote in message
news:11**********************@n15g2000prd.googlegr oups.com...
How can I add a child node to XML node "ItemID" below?
Thanks for assistance.
Dim oDOM : Set oDOM =
Server.CreateObject("MSXML2.DOMDocument.3.0")
oDOM.LoadXML "<rss version=""2.0""></rss>"
AddElem oDOM.documentElement, "ItemID", "15314"
Function AddElem(roParent, rsName, rvntValue)
Set AddElem = roParent.ownerDocument.createElement(rsName)
roParent.appendChild AddElem
If Not IsNull(rvntValue) AddElem.Text = rvntValue
End Function
Dim oItem
Set oItem = AddElem(oDOM.documentElement, "ItemID", "15314")
AddElem oItem, "subID", "AB"
This would create the XML:-
<rss version="2.0">
<ItemID>15314<subID>AB</subID></itemID>
</rss>
thank you. but how to append new child to subID?
Dim oItem, oSubItem

Set oItem = AddElem(oDOM.documentElement, "ItemID", "15314")
Set oSubItem = AddElem(oItem, "subID", Null)
AddElem oSubItem, "subsub", "Stuff"

Creates:-

<rss version="2.0">
<ItemID>15314<subID><subsub>Stuff</subsub></subID></itemID>
</rss>

Sorry for asking more, but... how can I add an attribute?
Dim oItem, oSubItem
Set oItem = AddElem(oDOM.documentElement, "ItemID", "15314")
Set oSubItem = AddElem(oItem, "subID", Null)
AddElem oSubItem, "subsub", "Stuff"
oSubItem.setAttrbute("thing", "blah")

generates:-

<rss version="2.0">
<ItemID>15314<subID><subsub thing="blah" >Stuff</subsub></subID></itemID>
</rss>

Try http://www.w3schools.com/

and

http://msdn.microsoft.com/library/en...16714e2824.asp


Jun 15 '07 #6
On Jun 15, 11:02 am, "Anthony Jones" <A...@yadayadayada.comwrote:
<vunet...@gmail.comwrote in message

news:11*********************@m36g2000hse.googlegro ups.com...
On Jun 14, 8:28 am, "Anthony Jones" <A...@yadayadayada.comwrote:
<vunet...@gmail.comwrote in message
>news:11**********************@e9g2000prf.googlegr oups.com...
On Jun 12, 3:26 am, "Anthony Jones" <A...@yadayadayada.comwrote:
<vunet...@gmail.comwrote in message
>news:11**********************@n15g2000prd.googleg roups.com...
How can I add a child node to XML node "ItemID" below?
Thanks for assistance.
Dim oDOM : Set oDOM =

Server.CreateObject("MSXML2.DOMDocument.3.0")
oDOM.LoadXML "<rss version=""2.0""></rss>"
AddElem oDOM.documentElement, "ItemID", "15314"
Function AddElem(roParent, rsName, rvntValue)
Set AddElem = roParent.ownerDocument.createElement(rsName)
roParent.appendChild AddElem
If Not IsNull(rvntValue) AddElem.Text = rvntValue
End Function
Dim oItem
Set oItem = AddElem(oDOM.documentElement, "ItemID", "15314")
AddElem oItem, "subID", "AB"
This would create the XML:-
<rss version="2.0">
<ItemID>15314<subID>AB</subID></itemID>
</rss>
thank you. but how to append new child to subID?
Dim oItem, oSubItem
Set oItem = AddElem(oDOM.documentElement, "ItemID", "15314")
Set oSubItem = AddElem(oItem, "subID", Null)
AddElem oSubItem, "subsub", "Stuff"
Creates:-
<rss version="2.0">
<ItemID>15314<subID><subsub>Stuff</subsub></subID></itemID>
</rss>
Sorry for asking more, but... how can I add an attribute?

Dim oItem, oSubItem
Set oItem = AddElem(oDOM.documentElement, "ItemID", "15314")
Set oSubItem = AddElem(oItem, "subID", Null)
AddElem oSubItem, "subsub", "Stuff"
oSubItem.setAttrbute("thing", "blah")

generates:-

<rss version="2.0">
<ItemID>15314<subID><subsub thing="blah" >Stuff</subsub></subID></itemID>
</rss>

Tryhttp://www.w3schools.com/

and

http://msdn.microsoft.com/library/en...a2722-7879-4e4...
Yes, thanks a lot. I'll try those links. Though now I am trying to
modify function to set attribute and it says:

Cannot use parentheses when calling a Sub
/vadmin/rss_items.asp, line 22
AddElemAttr.setAttribute(rvntAttr,rvntAttr)
-------------------------------------------^

Function AddElemAttr(roParent, rsName, rvntValue, rvntAttr,
rvntAttrValue)
Set AddElemAttr = roParent.ownerDocument.createElement(rsName)
roParent.appendChild AddElemAttr
If Not IsNull(rvntValue) then
AddElemAttr.Text = rvntValue
End If
If Not IsNull(rvntAttr) and rvntAttr <"" then
AddElemAttr.setAttribute(rvntAttr,rvntAttr)
'Set attr = roParent.ownerDocument.createAttribute("currency")
'AddElemAttr.setAttribute(attr)
End If
End Function

Set oItem = AddElem(oTitle, "item", Null)
AddElem oItem, "price", rsItem("Price") 'NEED ATTRIBUTE TO INSERT
AddElemAttr oItem, "edgeio:price", rsItem("Price"), "currency", "USD"

Jun 15 '07 #7
vu******@gmail.com wrote:
Yes, thanks a lot. I'll try those links. Though now I am trying to
modify function to set attribute and it says:

Cannot use parentheses when calling a Sub
/vadmin/rss_items.asp, line 22
AddElemAttr.setAttribute(rvntAttr,rvntAttr)
-------------------------------------------^
For once, we have an error message that means exactily what it says.
setAttribute is a method that does not return a value, aks, a "Sub"

See http://blogs.msdn.com/ericlippert/ar.../15/52996.aspx
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jun 15 '07 #8

<vu******@gmail.comwrote in message
news:11**********************@m36g2000hse.googlegr oups.com...
On Jun 15, 11:02 am, "Anthony Jones" <A...@yadayadayada.comwrote:
<vunet...@gmail.comwrote in message

news:11*********************@m36g2000hse.googlegro ups.com...
On Jun 14, 8:28 am, "Anthony Jones" <A...@yadayadayada.comwrote:
<vunet...@gmail.comwrote in message
news:11**********************@e9g2000prf.googlegro ups.com...
On Jun 12, 3:26 am, "Anthony Jones" <A...@yadayadayada.comwrote:
<vunet...@gmail.comwrote in message
news:11**********************@n15g2000prd.googlegr oups.com...
How can I add a child node to XML node "ItemID" below?
Thanks for assistance.
Dim oDOM : Set oDOM =
Server.CreateObject("MSXML2.DOMDocument.3.0")
oDOM.LoadXML "<rss version=""2.0""></rss>"
AddElem oDOM.documentElement, "ItemID", "15314"
Function AddElem(roParent, rsName, rvntValue)
Set AddElem =
roParent.ownerDocument.createElement(rsName)
roParent.appendChild AddElem
If Not IsNull(rvntValue) AddElem.Text = rvntValue
End Function
Dim oItem
Set oItem = AddElem(oDOM.documentElement, "ItemID", "15314")
AddElem oItem, "subID", "AB"
This would create the XML:-
<rss version="2.0">
<ItemID>15314<subID>AB</subID></itemID>
</rss>
thank you. but how to append new child to subID?
Dim oItem, oSubItem
Set oItem = AddElem(oDOM.documentElement, "ItemID", "15314")
Set oSubItem = AddElem(oItem, "subID", Null)
AddElem oSubItem, "subsub", "Stuff"
Creates:-
<rss version="2.0">
<ItemID>15314<subID><subsub>Stuff</subsub></subID></itemID>
</rss>
Sorry for asking more, but... how can I add an attribute?
Dim oItem, oSubItem
Set oItem = AddElem(oDOM.documentElement, "ItemID", "15314")
Set oSubItem = AddElem(oItem, "subID", Null)
AddElem oSubItem, "subsub", "Stuff"
oSubItem.setAttrbute("thing", "blah")

generates:-

<rss version="2.0">
<ItemID>15314<subID><subsub thing="blah"
Stuff</subsub></subID></itemID>
</rss>

Tryhttp://www.w3schools.com/

and

http://msdn.microsoft.com/library/en...a2722-7879-4e4...

Yes, thanks a lot. I'll try those links. Though now I am trying to
modify function to set attribute and it says:

Cannot use parentheses when calling a Sub
/vadmin/rss_items.asp, line 22
AddElemAttr.setAttribute(rvntAttr,rvntAttr)
-------------------------------------------^

Function AddElemAttr(roParent, rsName, rvntValue, rvntAttr,
rvntAttrValue)
Set AddElemAttr = roParent.ownerDocument.createElement(rsName)
roParent.appendChild AddElemAttr
If Not IsNull(rvntValue) then
AddElemAttr.Text = rvntValue
End If
If Not IsNull(rvntAttr) and rvntAttr <"" then
AddElemAttr.setAttribute(rvntAttr,rvntAttr)
'Set attr = roParent.ownerDocument.createAttribute("currency")
'AddElemAttr.setAttribute(attr)
End If
End Function

Set oItem = AddElem(oTitle, "item", Null)
AddElem oItem, "price", rsItem("Price") 'NEED ATTRIBUTE TO INSERT
AddElemAttr oItem, "edgeio:price", rsItem("Price"), "currency", "USD"
First off my fault my code should've looked like this:-

Dim oItem, oSubItem
Set oItem = AddElem(oDOM.documentElement, "ItemID", "15314")
Set oSubItem = AddElem(oItem, "subID", Null)
AddElem oSubItem, "subsub", "Stuff"
oSubItem.setAttribute "thing", "blah"

and i's output is actually:-

<rss version="2.0">
<ItemID>15314<subID thing="blah"><subsub>Stuff</subsub></subID></itemID>
</rss>
Secondly AddElemAttr?? Honestly just don't do that. A function should do
one thing and do that one thing well.
You are trying to create a function that does two things. What happens when
you want to create an element that has two attributes, are you going to
create yet another function for that?

Take this XML:-

<root>
<item>
<name>Hello</name>
<subItem ID="1">Stuff</subItem>
</item>
<item>
<name>World</name>
<subItem ID="2" other="ruhbarb">Blah</subItem>
</item>
</root>

This can built with this code:-

Dim oItem

Dim oDOM : Set oDOM = Server.CreateObject("MSXML2.DOMDocument.3.0")
oDOM.loadXML("<root />")

Set oItem = AddElem(oDOM.documentElement, "item", Null)
AddElem oItem, "name", "Hello"
AddElem(oItem, "subItem", "Stuff").setAttribute("ID", "1")

Set oItem = AddElem(oDOM.documentElement, "item", Null)
AddElem oItem, "name", "Hello"
With AddElem(oItem, "subItem", "Blah")
.setAttribute("ID", "2")
.setAttribute("other", "ruhbarb")
End With


Jun 15 '07 #9
On Jun 15, 11:50 am, "Anthony Jones" <A...@yadayadayada.comwrote:
<vunet...@gmail.comwrote in message

news:11**********************@m36g2000hse.googlegr oups.com...
On Jun 15, 11:02 am, "Anthony Jones" <A...@yadayadayada.comwrote:
<vunet...@gmail.comwrote in message
>news:11*********************@m36g2000hse.googlegr oups.com...
On Jun 14, 8:28 am, "Anthony Jones" <A...@yadayadayada.comwrote:
<vunet...@gmail.comwrote in message
>news:11**********************@e9g2000prf.googlegr oups.com...
On Jun 12, 3:26 am, "Anthony Jones" <A...@yadayadayada.comwrote:
<vunet...@gmail.comwrote in message
>news:11**********************@n15g2000prd.googleg roups.com...
How can I add a child node to XML node "ItemID" below?
Thanks for assistance.
Dim oDOM : Set oDOM =
Server.CreateObject("MSXML2.DOMDocument.3.0")
oDOM.LoadXML "<rss version=""2.0""></rss>"
AddElem oDOM.documentElement, "ItemID", "15314"
Function AddElem(roParent, rsName, rvntValue)
Set AddElem =

roParent.ownerDocument.createElement(rsName)
roParent.appendChild AddElem
If Not IsNull(rvntValue) AddElem.Text = rvntValue
End Function
Dim oItem
Set oItem = AddElem(oDOM.documentElement, "ItemID", "15314")
AddElem oItem, "subID", "AB"
This would create the XML:-
<rss version="2.0">
<ItemID>15314<subID>AB</subID></itemID>
</rss>
thank you. but how to append new child to subID?
Dim oItem, oSubItem
Set oItem = AddElem(oDOM.documentElement, "ItemID", "15314")
Set oSubItem = AddElem(oItem, "subID", Null)
AddElem oSubItem, "subsub", "Stuff"
Creates:-
<rss version="2.0">
<ItemID>15314<subID><subsub>Stuff</subsub></subID></itemID>
</rss>
Sorry for asking more, but... how can I add an attribute?
Dim oItem, oSubItem
Set oItem = AddElem(oDOM.documentElement, "ItemID", "15314")
Set oSubItem = AddElem(oItem, "subID", Null)
AddElem oSubItem, "subsub", "Stuff"
oSubItem.setAttrbute("thing", "blah")
generates:-
<rss version="2.0">
<ItemID>15314<subID><subsub thing="blah"
Stuff</subsub></subID></itemID>
</rss>
Tryhttp://www.w3schools.com/
and
>http://msdn.microsoft.com/library/en...a2722-7879-4e4...
Yes, thanks a lot. I'll try those links. Though now I am trying to
modify function to set attribute and it says:
Cannot use parentheses when calling a Sub
/vadmin/rss_items.asp, line 22
AddElemAttr.setAttribute(rvntAttr,rvntAttr)
-------------------------------------------^
Function AddElemAttr(roParent, rsName, rvntValue, rvntAttr,
rvntAttrValue)
Set AddElemAttr = roParent.ownerDocument.createElement(rsName)
roParent.appendChild AddElemAttr
If Not IsNull(rvntValue) then
AddElemAttr.Text = rvntValue
End If
If Not IsNull(rvntAttr) and rvntAttr <"" then
AddElemAttr.setAttribute(rvntAttr,rvntAttr)
'Set attr = roParent.ownerDocument.createAttribute("currency")
'AddElemAttr.setAttribute(attr)
End If
End Function
Set oItem = AddElem(oTitle, "item", Null)
AddElem oItem, "price", rsItem("Price") 'NEED ATTRIBUTE TO INSERT
AddElemAttr oItem, "edgeio:price", rsItem("Price"), "currency", "USD"

First off my fault my code should've looked like this:-

Dim oItem, oSubItem
Set oItem = AddElem(oDOM.documentElement, "ItemID", "15314")
Set oSubItem = AddElem(oItem, "subID", Null)
AddElem oSubItem, "subsub", "Stuff"
oSubItem.setAttribute "thing", "blah"

and i's output is actually:-

<rss version="2.0">
<ItemID>15314<subID thing="blah"><subsub>Stuff</subsub></subID></itemID>
</rss>

Secondly AddElemAttr?? Honestly just don't do that. A function should do
one thing and do that one thing well.
You are trying to create a function that does two things. What happens when
you want to create an element that has two attributes, are you going to
create yet another function for that?

Take this XML:-

<root>
<item>
<name>Hello</name>
<subItem ID="1">Stuff</subItem>
</item>
<item>
<name>World</name>
<subItem ID="2" other="ruhbarb">Blah</subItem>
</item>
</root>

This can built with this code:-

Dim oItem

Dim oDOM : Set oDOM = Server.CreateObject("MSXML2.DOMDocument.3.0")
oDOM.loadXML("<root />")

Set oItem = AddElem(oDOM.documentElement, "item", Null)
AddElem oItem, "name", "Hello"
AddElem(oItem, "subItem", "Stuff").setAttribute("ID", "1")

Set oItem = AddElem(oDOM.documentElement, "item", Null)
AddElem oItem, "name", "Hello"
With AddElem(oItem, "subItem", "Blah")
.setAttribute("ID", "2")
.setAttribute("other", "ruhbarb")
End With
but this still generates the same error "Cannot use parentheses when
calling a Sub":

AddElem oItem, "Type", "lskjdhf"
With AddElem(oItem, "price", rsItem("Price"))
.setAttribute("ID", "2")
.setAttribute("other", "ruhbarb")
End With

Jun 15 '07 #10

<vu******@gmail.comwrote in message
news:11**********************@o61g2000hsh.googlegr oups.com...
On Jun 15, 11:50 am, "Anthony Jones" <A...@yadayadayada.comwrote:
<vunet...@gmail.comwrote in message

news:11**********************@m36g2000hse.googlegr oups.com...
On Jun 15, 11:02 am, "Anthony Jones" <A...@yadayadayada.comwrote:
<vunet...@gmail.comwrote in message
news:11*********************@m36g2000hse.googlegro ups.com...
On Jun 14, 8:28 am, "Anthony Jones" <A...@yadayadayada.comwrote:
<vunet...@gmail.comwrote in message
news:11**********************@e9g2000prf.googlegro ups.com...
On Jun 12, 3:26 am, "Anthony Jones" <A...@yadayadayada.com>
wrote:
<vunet...@gmail.comwrote in message
news:11**********************@n15g2000prd.googlegr oups.com...
How can I add a child node to XML node "ItemID" below?
Thanks for assistance.
Dim oDOM : Set oDOM =
Server.CreateObject("MSXML2.DOMDocument.3.0")
oDOM.LoadXML "<rss version=""2.0""></rss>"
AddElem oDOM.documentElement, "ItemID", "15314"
Function AddElem(roParent, rsName, rvntValue)
Set AddElem =
roParent.ownerDocument.createElement(rsName)
roParent.appendChild AddElem
If Not IsNull(rvntValue) AddElem.Text = rvntValue
End Function
Dim oItem
Set oItem = AddElem(oDOM.documentElement, "ItemID", "15314")
AddElem oItem, "subID", "AB"
This would create the XML:-
<rss version="2.0">
<ItemID>15314<subID>AB</subID></itemID>
</rss>
thank you. but how to append new child to subID?
Dim oItem, oSubItem
Set oItem = AddElem(oDOM.documentElement, "ItemID", "15314")
Set oSubItem = AddElem(oItem, "subID", Null)
AddElem oSubItem, "subsub", "Stuff"
Creates:-
<rss version="2.0">
<ItemID>15314<subID><subsub>Stuff</subsub></subID></itemID>
</rss>
Sorry for asking more, but... how can I add an attribute?
Dim oItem, oSubItem
Set oItem = AddElem(oDOM.documentElement, "ItemID", "15314")
Set oSubItem = AddElem(oItem, "subID", Null)
AddElem oSubItem, "subsub", "Stuff"
oSubItem.setAttrbute("thing", "blah")
generates:-
<rss version="2.0">
<ItemID>15314<subID><subsub thing="blah"
>Stuff</subsub></subID></itemID>
</rss>
Tryhttp://www.w3schools.com/
and
>
http://msdn.microsoft.com/library/en...a2722-7879-4e4...
Yes, thanks a lot. I'll try those links. Though now I am trying to
modify function to set attribute and it says:
Cannot use parentheses when calling a Sub
/vadmin/rss_items.asp, line 22
AddElemAttr.setAttribute(rvntAttr,rvntAttr)
-------------------------------------------^
Function AddElemAttr(roParent, rsName, rvntValue, rvntAttr,
rvntAttrValue)
Set AddElemAttr = roParent.ownerDocument.createElement(rsName)
roParent.appendChild AddElemAttr
If Not IsNull(rvntValue) then
AddElemAttr.Text = rvntValue
End If
If Not IsNull(rvntAttr) and rvntAttr <"" then
AddElemAttr.setAttribute(rvntAttr,rvntAttr)
'Set attr = roParent.ownerDocument.createAttribute("currency")
'AddElemAttr.setAttribute(attr)
End If
End Function
Set oItem = AddElem(oTitle, "item", Null)
AddElem oItem, "price", rsItem("Price") 'NEED ATTRIBUTE TO INSERT
AddElemAttr oItem, "edgeio:price", rsItem("Price"), "currency", "USD"
First off my fault my code should've looked like this:-

Dim oItem, oSubItem
Set oItem = AddElem(oDOM.documentElement, "ItemID", "15314")
Set oSubItem = AddElem(oItem, "subID", Null)
AddElem oSubItem, "subsub", "Stuff"
oSubItem.setAttribute "thing", "blah"

and i's output is actually:-

<rss version="2.0">
<ItemID>15314<subID
thing="blah"><subsub>Stuff</subsub></subID></itemID>
</rss>

Secondly AddElemAttr?? Honestly just don't do that. A function should
do
one thing and do that one thing well.
You are trying to create a function that does two things. What happens
when
you want to create an element that has two attributes, are you going to
create yet another function for that?

Take this XML:-

<root>
<item>
<name>Hello</name>
<subItem ID="1">Stuff</subItem>
</item>
<item>
<name>World</name>
<subItem ID="2" other="ruhbarb">Blah</subItem>
</item>
</root>

This can built with this code:-

Dim oItem

Dim oDOM : Set oDOM = Server.CreateObject("MSXML2.DOMDocument.3.0")
oDOM.loadXML("<root />")

Set oItem = AddElem(oDOM.documentElement, "item", Null)
AddElem oItem, "name", "Hello"
AddElem(oItem, "subItem", "Stuff").setAttribute("ID", "1")

Set oItem = AddElem(oDOM.documentElement, "item", Null)
AddElem oItem, "name", "Hello"
With AddElem(oItem, "subItem", "Blah")
.setAttribute("ID", "2")
.setAttribute("other", "ruhbarb")
End With

but this still generates the same error "Cannot use parentheses when
calling a Sub":

AddElem oItem, "Type", "lskjdhf"
With AddElem(oItem, "price", rsItem("Price"))
.setAttribute("ID", "2")
.setAttribute("other", "ruhbarb")
End With
I did it again didn't I (flicking between JScript and VBScript is quite
maddening). Tell me, what do think needs to be done to fix that?
Jun 15 '07 #11
On Jun 15, 12:25 pm, "Anthony Jones" <A...@yadayadayada.comwrote:
<vunet...@gmail.comwrote in message

news:11**********************@o61g2000hsh.googlegr oups.com...
On Jun 15, 11:50 am, "Anthony Jones" <A...@yadayadayada.comwrote:
<vunet...@gmail.comwrote in message
>news:11**********************@m36g2000hse.googleg roups.com...
On Jun 15, 11:02 am, "Anthony Jones" <A...@yadayadayada.comwrote:
<vunet...@gmail.comwrote in message
>news:11*********************@m36g2000hse.googlegr oups.com...
On Jun 14, 8:28 am, "Anthony Jones" <A...@yadayadayada.comwrote:
<vunet...@gmail.comwrote in message
>news:11**********************@e9g2000prf.googlegr oups.com...
On Jun 12, 3:26 am, "Anthony Jones" <A...@yadayadayada.com>
wrote:
<vunet...@gmail.comwrote in message
>news:11**********************@n15g2000prd.googleg roups.com...
How can I add a child node to XML node "ItemID" below?
Thanks for assistance.
Dim oDOM : Set oDOM =
Server.CreateObject("MSXML2.DOMDocument.3.0")
oDOM.LoadXML "<rss version=""2.0""></rss>"
AddElem oDOM.documentElement, "ItemID", "15314"
Function AddElem(roParent, rsName, rvntValue)
Set AddElem =
roParent.ownerDocument.createElement(rsName)
roParent.appendChild AddElem
If Not IsNull(rvntValue) AddElem.Text = rvntValue
End Function
Dim oItem
Set oItem = AddElem(oDOM.documentElement, "ItemID", "15314")
AddElem oItem, "subID", "AB"
This would create the XML:-
<rss version="2.0">
<ItemID>15314<subID>AB</subID></itemID>
</rss>
thank you. but how to append new child to subID?
Dim oItem, oSubItem
Set oItem = AddElem(oDOM.documentElement, "ItemID", "15314")
Set oSubItem = AddElem(oItem, "subID", Null)
AddElem oSubItem, "subsub", "Stuff"
Creates:-
<rss version="2.0">
<ItemID>15314<subID><subsub>Stuff</subsub></subID></itemID>
</rss>
Sorry for asking more, but... how can I add an attribute?
Dim oItem, oSubItem
Set oItem = AddElem(oDOM.documentElement, "ItemID", "15314")
Set oSubItem = AddElem(oItem, "subID", Null)
AddElem oSubItem, "subsub", "Stuff"
oSubItem.setAttrbute("thing", "blah")
generates:-
<rss version="2.0">
<ItemID>15314<subID><subsub thing="blah"
Stuff</subsub></subID></itemID>
</rss>
Tryhttp://www.w3schools.com/
and
http://msdn.microsoft.com/library/en...a2722-7879-4e4...
Yes, thanks a lot. I'll try those links. Though now I am trying to
modify function to set attribute and it says:
Cannot use parentheses when calling a Sub
/vadmin/rss_items.asp, line 22
AddElemAttr.setAttribute(rvntAttr,rvntAttr)
-------------------------------------------^
Function AddElemAttr(roParent, rsName, rvntValue, rvntAttr,
rvntAttrValue)
Set AddElemAttr = roParent.ownerDocument.createElement(rsName)
roParent.appendChild AddElemAttr
If Not IsNull(rvntValue) then
AddElemAttr.Text = rvntValue
End If
If Not IsNull(rvntAttr) and rvntAttr <"" then
AddElemAttr.setAttribute(rvntAttr,rvntAttr)
'Set attr = roParent.ownerDocument.createAttribute("currency")
'AddElemAttr.setAttribute(attr)
End If
End Function
Set oItem = AddElem(oTitle, "item", Null)
AddElem oItem, "price", rsItem("Price") 'NEED ATTRIBUTE TO INSERT
AddElemAttr oItem, "edgeio:price", rsItem("Price"), "currency", "USD"
First off my fault my code should've looked like this:-
Dim oItem, oSubItem
Set oItem = AddElem(oDOM.documentElement, "ItemID", "15314")
Set oSubItem = AddElem(oItem, "subID", Null)
AddElem oSubItem, "subsub", "Stuff"
oSubItem.setAttribute "thing", "blah"
and i's output is actually:-
<rss version="2.0">
<ItemID>15314<subID

thing="blah"><subsub>Stuff</subsub></subID></itemID>
</rss>
Secondly AddElemAttr?? Honestly just don't do that. A function should
do
one thing and do that one thing well.
You are trying to create a function that does two things. What happens
when
you want to create an element that has two attributes, are you going to
create yet another function for that?
Take this XML:-
<root>
<item>
<name>Hello</name>
<subItem ID="1">Stuff</subItem>
</item>
<item>
<name>World</name>
<subItem ID="2" other="ruhbarb">Blah</subItem>
</item>
</root>
This can built with this code:-
Dim oItem
Dim oDOM : Set oDOM = Server.CreateObject("MSXML2.DOMDocument.3.0")
oDOM.loadXML("<root />")
Set oItem = AddElem(oDOM.documentElement, "item", Null)
AddElem oItem, "name", "Hello"
AddElem(oItem, "subItem", "Stuff").setAttribute("ID", "1")
Set oItem = AddElem(oDOM.documentElement, "item", Null)
AddElem oItem, "name", "Hello"
With AddElem(oItem, "subItem", "Blah")
.setAttribute("ID", "2")
.setAttribute("other", "ruhbarb")
End With
but this still generates the same error "Cannot use parentheses when
calling a Sub":
AddElem oItem, "Type", "lskjdhf"
With AddElem(oItem, "price", rsItem("Price"))
.setAttribute("ID", "2")
.setAttribute("other", "ruhbarb")
End With

I did it again didn't I (flicking between JScript and VBScript is quite
maddening). Tell me, what do think needs to be done to fix that?
all right, all right... I'll do some reading...

Jun 15 '07 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: William C. White | last post by:
Does anyone know of a way to use PHP /w Authorize.net AIM without using cURL? Our website is hosted on a shared drive and the webhost company doesn't installed additional software (such as cURL)...
2
by: Albert Ahtenberg | last post by:
Hello, I don't know if it is only me but I was sure that header("Location:url") redirects the browser instantly to URL, or at least stops the execution of the code. But appearantely it continues...
3
by: James | last post by:
Hi, I have a form with 2 fields. 'A' 'B' The user completes one of the fields and the form is submitted. On the results page I want to run a query, but this will change subject to which...
0
by: Ollivier Robert | last post by:
Hello, I'm trying to link PHP with Oracle 9.2.0/OCI8 with gcc 3.2.3 on a Solaris9 system. The link succeeds but everytime I try to run php, I get a SEGV from inside the libcnltsh.so library. ...
1
by: Richard Galli | last post by:
I want viewers to compare state laws on a single subject. Imagine a three-column table with a drop-down box on the top. A viewer selects a state from the list, and that state's text fills the...
4
by: Albert Ahtenberg | last post by:
Hello, I have two questions. 1. When the user presses the back button and returns to a form he filled the form is reseted. How do I leave there the values he inserted? 2. When the...
1
by: inderjit S Gabrie | last post by:
Hi all Here is the scenerio ...is it possibly to do this... i am getting valid course dates output on to a web which i have designed ....all is okay so far , look at the following web url ...
2
by: Jack | last post by:
Hi All, What is the PHP equivilent of Oracle bind variables in a SQL statement, e.g. select x from y where z=:parameter Which in asp/jsp would be followed by some statements to bind a value...
3
by: Sandwick | last post by:
I am trying to change the size of a drawing so they are all 3x3. the script below is what i was trying to use to cut it in half ... I get errors. I can display the normal picture but not the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.