• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1475
  • Last Modified:

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("Microsoft.XMLDOM")
Set oXMLRec = oXML.createElement("UtilityId")  
oXMLRec.setAttribute "ID", myaccount
oXMLRec.setAttribute "zipCode", myzip
oXML.documentElement.appendChild(oXMLRec)

<?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>
0
Hojoformo
Asked:
Hojoformo
  • 2
1 Solution
 
steveberzinsCommented:
how about this?

Set oXML = Server.CreateObject("Microsoft.XMLDOM")

Set oXMLRec = oXML.createElement("UtilityId")  
oXMLRec.setAttribute "ID", myaccount

Set oXMLZip = oXML.createElement("zipCode")  
oXMLZip.text = "12345"
oXMLRec.appendChild(oXMLZip)

oXML.documentElement.appendChild(oXMLRec)
0
 
bugs021997Commented:
dim objNode, objDOM

      'Create an XML DOM object from the XML file
      Set objDOM  = CreateObject("Microsoft.XMLDOM")            
      objDOM.async = false
      objDOM.load("yourFile.xml")

      'Display the original XML values
      txtOrig.value = objDOM.xml
      
      'Create a new Node object
      Set objNode = objDOM.getElementsByTagName("UtilityId")

      '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
0
 
bugs021997Commented:
Using Javascript you can do the same as below

<script language="javascript">

xmlDoc=loadXMLDoc("books.xml");

var x=xmlDoc.getElementsByTagName('UtilityId');
var newatt;

for (i=0;i<x.length;i++)
  {
  newatt=xmlDoc.createAttribute("zipCode");
  newatt.value="12345";
  x[i].setAttributeNode(newatt);
  }

</script>
0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now