Hojoformo
asked on
Creating a New XML Node using Classic ASP/XMLDOM.
Need a little assistance creating a new XML node. I need to create a new node called "zipCode" right under the existing node "UtilityId". For example, I want my xml to look like:
<UtilityId ID="1829118006" />
<zipCode>12345</zipCode>
This is how I am currently doing it but I now this is not right.
Set oXML = Server.CreateObject("Micro soft.XMLDO M")
Set oXMLRec = oXML.createElement("Utilit yId")
oXMLRec.setAttribute "ID", myaccount
oXMLRec.setAttribute "zipCode", myzip
oXML.documentElement.appen dChild(oXM LRec)
<?xml version="1.0" encoding="ISO-8859-1" ?>
- <BillingData xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://apogee.net/WebService">
<UtilityId ID="2222570016" zipCode="30907" /> ???? zipcode needs to be it's own node.
<billingCycleData />
</BillingData>
<UtilityId ID="1829118006" />
<zipCode>12345</zipCode>
This is how I am currently doing it but I now this is not right.
Set oXML = Server.CreateObject("Micro
Set oXMLRec = oXML.createElement("Utilit
oXMLRec.setAttribute "ID", myaccount
oXMLRec.setAttribute "zipCode", myzip
oXML.documentElement.appen
<?xml version="1.0" encoding="ISO-8859-1" ?>
- <BillingData xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://apogee.net/WebService">
<UtilityId ID="2222570016" zipCode="30907" /> ???? zipcode needs to be it's own node.
<billingCycleData />
</BillingData>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Using Javascript you can do the same as below
<script language="javascript">
xmlDoc=loadXMLDoc("books.x ml");
var x=xmlDoc.getElementsByTagN ame('Utili tyId');
var newatt;
for (i=0;i<x.length;i++)
{
newatt=xmlDoc.createAttrib ute("zipCo de");
newatt.value="12345";
x[i].setAttributeNode(newa tt);
}
</script>
<script language="javascript">
xmlDoc=loadXMLDoc("books.x
var x=xmlDoc.getElementsByTagN
var newatt;
for (i=0;i<x.length;i++)
{
newatt=xmlDoc.createAttrib
newatt.value="12345";
x[i].setAttributeNode(newa
}
</script>
Forced accept.
Computer101
EE Admin
Computer101
EE Admin
'Create an XML DOM object from the XML file
Set objDOM = CreateObject("Microsoft.XM
objDOM.async = false
objDOM.load("yourFile.xml"
'Display the original XML values
txtOrig.value = objDOM.xml
'Create a new Node object
Set objNode = objDOM.getElementsByTagNam
'Add the objects to the newly created Node
AddNodeAttribute objDOM, objNode, "zipCode", "12345"
'If you want to add another one then uncomment below line
'AddNodeAttribute objDOM, objNode, "nodeName", "valueForNode"
response.write objDOM.xml