In XML, creating an attribute once and use it many times using VBScript -
i need add same attribute different nodes. there way define attribute once , use many times ?
here tried do:
set myattribute = xmldoc.createattribute("operation") attribute.value = "delete"
now can following:
node.attributes.setnameditem(myattribute)
but if want add same attribute node, error. like:
node2.attributes.setnameditem(myattribute)
so, there way re-use attribute without repeating first 2 lines of code?
in code, myattribute
variable object reference points same time. need clone node. have @ clonenode method.
set xmldoc = createobject("msxml2.domdocument") xmldoc.loadxml "<root/>" set theelement = xmldoc.createelement("element") set theattribute = xmldoc.createattribute("attribute") theattribute.value = "delete" = 1 15 xmldoc.documentelement.appendchild(theelement.clonenode(true)) .attributes.setnameditem(theattribute.clonenode(true)) end next wscript.echo xmldoc.xml
output (indented , prettified manually):
<root> <element attribute="delete"/> <element attribute="delete"/> <element attribute="delete"/> <element attribute="delete"/> <element attribute="delete"/> <element attribute="delete"/> <element attribute="delete"/> <element attribute="delete"/> <element attribute="delete"/> <element attribute="delete"/> <element attribute="delete"/> <element attribute="delete"/> <element attribute="delete"/> <element attribute="delete"/> <element attribute="delete"/> </root>
Comments
Post a Comment