XML and ASP
am 12.06.2007 05:46:57 von vunet.us
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 ""
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
Re: XML and ASP
am 12.06.2007 10:26:51 von Anthony Jones
wrote in message
news:1181620017.663877.240490@n15g2000prd.googlegroups.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 ""
> 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:-
15314AB
Re: XML and ASP
am 14.06.2007 13:28:11 von vunet.us
On Jun 12, 3:26 am, "Anthony Jones" wrote:
> wrote in message
>
> news:1181620017.663877.240490@n15g2000prd.googlegroups.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 ""
> > 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:-
>
>
> 15314AB
>
thank you. but how to append new child to subID?
Re: XML and ASP
am 14.06.2007 15:28:02 von Anthony Jones
wrote in message
news:1181820491.533884.210020@e9g2000prf.googlegroups.com...
> On Jun 12, 3:26 am, "Anthony Jones" wrote:
> > wrote in message
> >
> > news:1181620017.663877.240490@n15g2000prd.googlegroups.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 ""
> > > 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:-
> >
> >
> > 15314AB
> >
>
> 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:-
15314Stuff
Re: XML and ASP
am 15.06.2007 16:59:48 von vunet.us
On Jun 14, 8:28 am, "Anthony Jones" wrote:
> wrote in message
>
> news:1181820491.533884.210020@e9g2000prf.googlegroups.com...
>
>
>
> > On Jun 12, 3:26 am, "Anthony Jones" wrote:
> > > wrote in message
>
> > >news:1181620017.663877.240490@n15g2000prd.googlegroups.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 ""
> > > > 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:-
>
> > >
> > > 15314AB
> > >
>
> > 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:-
>
>
> 15314Stuff
>
Sorry for asking more, but... how can I add an attribute?
Re: XML and ASP
am 15.06.2007 18:02:04 von Anthony Jones
wrote in message
news:1181919588.896414.90360@m36g2000hse.googlegroups.com...
> On Jun 14, 8:28 am, "Anthony Jones" wrote:
> > wrote in message
> >
> > news:1181820491.533884.210020@e9g2000prf.googlegroups.com...
> >
> >
> >
> > > On Jun 12, 3:26 am, "Anthony Jones" wrote:
> > > > wrote in message
> >
> > > >news:1181620017.663877.240490@n15g2000prd.googlegroups.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 ""
> > > > > 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:-
> >
> > > >
> > > > 15314AB
> > > >
> >
> > > 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:-
> >
> >
> > 15314Stuff
> >
>
> 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:-
15314Stuff
Try http://www.w3schools.com/
and
http://msdn.microsoft.com/library/en-us/xmlsdk/html/e9da2722 -7879-4e48-869c-7f16714e2824.asp
Re: XML and ASP
am 15.06.2007 18:16:01 von vunet.us
On Jun 15, 11:02 am, "Anthony Jones" wrote:
> wrote in message
>
> news:1181919588.896414.90360@m36g2000hse.googlegroups.com...
>
> > On Jun 14, 8:28 am, "Anthony Jones" wrote:
> > > wrote in message
>
> > >news:1181820491.533884.210020@e9g2000prf.googlegroups.com.. .
>
> > > > On Jun 12, 3:26 am, "Anthony Jones" wrote:
> > > > > wrote in message
>
> > > > >news:1181620017.663877.240490@n15g2000prd.googlegroups.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 ""
> > > > > > 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:-
>
> > > > >
> > > > > 15314AB
> > > > >
>
> > > > 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:-
>
> > >
> > > 15314Stuff
> > >
>
> > 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:-
>
>
> 15314Stuff
>
>
> Tryhttp://www.w3schools.com/
>
> and
>
> http://msdn.microsoft.com/library/en-us/xmlsdk/html/e9da2722 -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"
Re: XML and ASP
am 15.06.2007 18:44:17 von reb01501
vunet.us@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/archive/2003/09/15/52996.a spx
--
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"
Re: XML and ASP
am 15.06.2007 18:50:15 von Anthony Jones
wrote in message
news:1181924161.653705.264020@m36g2000hse.googlegroups.com.. .
> On Jun 15, 11:02 am, "Anthony Jones" wrote:
> > wrote in message
> >
> > news:1181919588.896414.90360@m36g2000hse.googlegroups.com...
> >
> > > On Jun 14, 8:28 am, "Anthony Jones" wrote:
> > > > wrote in message
> >
> > > >news:1181820491.533884.210020@e9g2000prf.googlegroups.com.. .
> >
> > > > > On Jun 12, 3:26 am, "Anthony Jones" wrote:
> > > > > > wrote in message
> >
> > > > > >news:1181620017.663877.240490@n15g2000prd.googlegroups.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 ""
> > > > > > > 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:-
> >
> > > > > >
> > > > > > 15314AB
> > > > > >
> >
> > > > > 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:-
> >
> > > >
> > > > 15314Stuff
> > > >
> >
> > > 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:-
> >
> >
> > 15314
>Stuff
> >
> >
> > Tryhttp://www.w3schools.com/
> >
> > and
> >
> > http://msdn.microsoft.com/library/en-us/xmlsdk/html/e9da2722 -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:-
15314Stuff
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:-
Hello
Stuff
World
Blah
This can built with this code:-
Dim oItem
Dim oDOM : Set oDOM = Server.CreateObject("MSXML2.DOMDocument.3.0")
oDOM.loadXML("")
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
Re: XML and ASP
am 15.06.2007 19:16:39 von vunet.us
On Jun 15, 11:50 am, "Anthony Jones" wrote:
> wrote in message
>
> news:1181924161.653705.264020@m36g2000hse.googlegroups.com.. .
>
> > On Jun 15, 11:02 am, "Anthony Jones" wrote:
> > > wrote in message
>
> > >news:1181919588.896414.90360@m36g2000hse.googlegroups.com.. .
>
> > > > On Jun 14, 8:28 am, "Anthony Jones" wrote:
> > > > > wrote in message
>
> > > > >news:1181820491.533884.210020@e9g2000prf.googlegroups.com.. .
>
> > > > > > On Jun 12, 3:26 am, "Anthony Jones" wrote:
> > > > > > > wrote in message
>
> > > > > > >news:1181620017.663877.240490@n15g2000prd.googlegroups.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 ""
> > > > > > > > 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:-
>
> > > > > > >
> > > > > > > 15314AB
> > > > > > >
>
> > > > > > 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:-
>
> > > > >
> > > > > 15314Stuff
> > > > >
>
> > > > 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:-
>
> > >
> > > 15314
> >Stuff
> > >
>
> > > Tryhttp://www.w3schools.com/
>
> > > and
>
> > >http://msdn.microsoft.com/library/en-us/xmlsdk/html/e9da272 2-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:-
>
>
> 15314Stuff
>
>
> 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:-
>
>
>
> Hello
> Stuff
>
>
> World
> Blah
>
>
>
> This can built with this code:-
>
> Dim oItem
>
> Dim oDOM : Set oDOM = Server.CreateObject("MSXML2.DOMDocument.3.0")
> oDOM.loadXML("")
>
> 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
Re: XML and ASP
am 15.06.2007 19:25:16 von Anthony Jones
wrote in message
news:1181927799.445952.158880@o61g2000hsh.googlegroups.com.. .
> On Jun 15, 11:50 am, "Anthony Jones" wrote:
> > wrote in message
> >
> > news:1181924161.653705.264020@m36g2000hse.googlegroups.com.. .
> >
> > > On Jun 15, 11:02 am, "Anthony Jones" wrote:
> > > > wrote in message
> >
> > > >news:1181919588.896414.90360@m36g2000hse.googlegroups.com.. .
> >
> > > > > On Jun 14, 8:28 am, "Anthony Jones" wrote:
> > > > > > wrote in message
> >
> > > > > >news:1181820491.533884.210020@e9g2000prf.googlegroups.com.. .
> >
> > > > > > > On Jun 12, 3:26 am, "Anthony Jones"
wrote:
> > > > > > > > wrote in message
> >
> > > > > > > >news:1181620017.663877.240490@n15g2000prd.googlegroups.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 ""
> > > > > > > > > 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:-
> >
> > > > > > > >
> > > > > > > > 15314AB
> > > > > > > >
> >
> > > > > > > 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:-
> >
> > > > > >
> > > > > > 15314Stuff
> > > > > >
> >
> > > > > 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:-
> >
> > > >
> > > > 15314
> > >Stuff
> > > >
> >
> > > > Tryhttp://www.w3schools.com/
> >
> > > > and
> >
> > >
>http://msdn.microsoft.com/library/en-us/xmlsdk/html/e9da272 2-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:-
> >
> >
> > 15314
thing="blah">Stuff
> >
> >
> > 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:-
> >
> >
> >
> > Hello
> > Stuff
> >
> >
> > World
> > Blah
> >
> >
> >
> > This can built with this code:-
> >
> > Dim oItem
> >
> > Dim oDOM : Set oDOM = Server.CreateObject("MSXML2.DOMDocument.3.0")
> > oDOM.loadXML("")
> >
> > 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?
Re: XML and ASP
am 15.06.2007 21:47:48 von vunet.us
On Jun 15, 12:25 pm, "Anthony Jones" wrote:
> wrote in message
>
> news:1181927799.445952.158880@o61g2000hsh.googlegroups.com.. .
>
> > On Jun 15, 11:50 am, "Anthony Jones" wrote:
> > > wrote in message
>
> > >news:1181924161.653705.264020@m36g2000hse.googlegroups.com. ..
>
> > > > On Jun 15, 11:02 am, "Anthony Jones" wrote:
> > > > > wrote in message
>
> > > > >news:1181919588.896414.90360@m36g2000hse.googlegroups.com.. .
>
> > > > > > On Jun 14, 8:28 am, "Anthony Jones" wrote:
> > > > > > > wrote in message
>
> > > > > > >news:1181820491.533884.210020@e9g2000prf.googlegroups.com.. .
>
> > > > > > > > On Jun 12, 3:26 am, "Anthony Jones"
> wrote:
> > > > > > > > > wrote in message
>
> > > > > > > > >news:1181620017.663877.240490@n15g2000prd.googlegroups.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 ""
> > > > > > > > > > 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:-
>
> > > > > > > > >
> > > > > > > > > 15314AB
> > > > > > > > >
>
> > > > > > > > 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:-
>
> > > > > > >
> > > > > > > 15314Stuff
> > > > > > >
>
> > > > > > 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:-
>
> > > > >
> > > > > 15314
> > > >Stuff
> > > > >
>
> > > > > Tryhttp://www.w3schools.com/
>
> > > > > and
>
> >http://msdn.microsoft.com/library/en-us/xmlsdk/html/e9da272 2-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:-
>
> > >
> > > 15314
>
> thing="blah">Stuff
>
>
>
> > >
>
> > > 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:-
>
> > >
> > >
> > > Hello
> > > Stuff
> > >
> > >
> > > World
> > > Blah
> > >
> > >
>
> > > This can built with this code:-
>
> > > Dim oItem
>
> > > Dim oDOM : Set oDOM = Server.CreateObject("MSXML2.DOMDocument.3.0")
> > > oDOM.loadXML("")
>
> > > 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...