[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1463
  • Last Modified:

VBScript to XML

EE Gods...
If you look below, the attribute "xmlns" shows up in all of my tags.
I only want it in two of them, and be ignored on the rest.
I cannot use namespaces, ie. xmlns:cc as this makes the SOAP service fail.
I do not have control of the service.  it is the webservice called "ConstantContact"

help?

<entry xmlns="http://www.w3.org/2005/Atom">
  <title xmlns="" type="text"/>
  <updated xmlns="">1/4/2010</updated>
  <author xmlns=""/>
  <id xmlns="">data:,none</id>
  <summary xmlns="" type="text">Contact</summary>
  <content xmlns="" type="application/vnd.ctct+xml">
    <contact xmlns="http://ws.constantcontact.com/ns/1.0/">
      <EmailAddress xmlns="">abc@yahoo.com</EmailAddress>
      <Name xmlns="">John Smith</Name>
      <OptInSource xmlns="">ACTION_BY_CUSTOMER</OptInSource>
      <ContactLists xmlns="">
        <ContactList id="https://api.constantcontact.com/ws/customers/AIDSRESEARCH/lists/5"/>
      </ContactLists>
    </contact>
  </content>
</entry>
Set objDom = Server.CreateObject("Msxml2.DOMDocument.3.0")
 Set objRoot = objDom.createElement("entry")
 Set objAttrib = objDom.createAttribute("xmlns")
 objAttrib.text = "http://www.w3.org/2005/Atom"
 objRoot.setAttributeNode objAttrib
 objDom.appendChild objRoot
 
 Set objTitle = objDom.createElement("title")
 Set objAttrib = objDom.createAttribute("type")
 objAttrib.text = "text"
 objTitle.setAttributeNode objAttrib
 objRoot.appendChild objTitle
 
 Set objUpdated = objDom.createElement("updated")
 objUpdated.text = Date()
 objRoot.appendChild objUpdated
 Set objChild = objDom.createElement("author")
 objRoot.appendChild objChild
 
 Set objId = objDom.createElement("id")
 objId.text = "data:,none"
 objRoot.appendChild objId

 Set objSummary = objDom.createElement("summary")
 Set objAttrib = objDom.createAttribute("type")
 objAttrib.text = "text"
 objSummary.setAttributeNode objAttrib
 objSummary.text = "Contact"
 objRoot.appendChild objSummary
 
 Dim content
 Set content = objDom.createElement("content")
 Set objAttrib = objDom.createAttribute("type")
 objAttrib.text = "application/vnd.ctct+xml"
 content.setAttributeNode objAttrib
 objRoot.appendChild content
 
 Dim contact
 Set contact = objDom.createElement("contact")
 Set objAttrib = objDom.createAttribute("xmlns")
 objAttrib.text = "http://ws.constantcontact.com/ns/1.0/"
 contact.setAttributeNode objAttrib
 content.appendChild contact

 
 Dim contactinfo
 Set contactinfo = objDom.createElement("EmailAddress")
 contactinfo.text = "abc@yahoo.com"
 contact.appendChild contactinfo
 
 Set contactinfo = objDom.createElement("Name")
 contactinfo.text = "John Smith"
 contact.appendChild contactinfo

 Set contactinfo = objDom.createElement("OptInSource")
 contactinfo.text = "ACTION_BY_CUSTOMER"
 contact.appendChild contactinfo
 
 Dim ContactLists
 Set ContactLists = objDom.createElement("ContactLists")
 contact.appendChild ContactLists
 
 Dim ContactList
 Set ContactList = objDom.createElement("ContactList")
 Set objAttrib = objDom.createAttribute("id")
 objAttrib.text = "https://api.constantcontact.com/ws/customers/" & UN & "/lists/5"
 ContactList.setAttributeNode objAttrib
 ContactLists.appendChild ContactList
 
  objDom.Save server.MapPath("App_Data\MyXMLDoc.xml")

Open in new window

0
Evan Cutler
Asked:
Evan Cutler
  • 2
  • 2
1 Solution
 
_Stilgar_Commented:
As weird as it may sound, I would rather use plain string concatenation to create XMLs in ASP Classic. It is faster, ligther, and  you have much more control over it. Try that and see for yourself...
0
 
PaulHewsCommented:
If you use createElement, you will not have correct namespace information... You need to use createNode where namespaces are being utilized.
 Set objDom = Server.CreateObject("Msxml2.DOMDocument.3.0")
 Dim ns
 ns = "http://www.w3.org/2005/Atom"
 Set objRoot = objDom.createNode(1, "entry", ns)
 
 objDom.appendChild objRoot
 
 Set objTitle = objDom.createNode(1, "title", ns)
 Set objAttrib = objDom.createAttribute("type")
 objAttrib.text = "text"
 objTitle.setAttributeNode objAttrib
 objRoot.appendChild objTitle
 
 Set objUpdated = objDom.createNode(1, "updated", ns)
 objUpdated.text = Date()
 objRoot.appendChild objUpdated
 Set objChild = objDom.createNode(1, "author", ns)
 objRoot.appendChild objChild
 
 Set objId = objDom.createNode(1, "id", ns)
 objId.text = "data:,none"
 objRoot.appendChild objId

 Set objSummary = objDom.createNode(1, "summary", ns)
 Set objAttrib = objDom.createAttribute("type")
 objAttrib.text = "text"
 objSummary.setAttributeNode objAttrib
 objSummary.text = "Contact"
 objRoot.appendChild objSummary
 
 Dim content
 Set content = objDom.createNode(1, "content", ns)
 Set objAttrib = objDom.createAttribute("type")
 objAttrib.text = "application/vnd.ctct+xml"
 content.setAttributeNode objAttrib
 objRoot.appendChild content
 
 Dim cns
 Dim contact
 cns = "http://ws.constantcontact.com/ns/1.0/"
 Set contact = objDom.createNode(1, "contact", cns)
 
 content.appendChild contact

 
 Dim contactinfo
 Set contactinfo = objDom.createNode(1, "EmailAddress", cns)
 contactinfo.text = "abc@yahoo.com"
 contact.appendChild contactinfo
 
 Set contactinfo = objDom.createNode(1, "Name", cns)
 contactinfo.text = "John Smith"
 contact.appendChild contactinfo

 Set contactinfo = objDom.createNode(1, "OptInSource", cns)
 contactinfo.text = "ACTION_BY_CUSTOMER"
 contact.appendChild contactinfo
 
 Dim ContactLists
 Set ContactLists = objDom.createNode(1, "ContactLists", cns)
 contact.appendChild ContactLists
 
 Dim ContactList
 Set ContactList = objDom.createNode(1, "ContactList", cns)
 Set objAttrib = objDom.createAttribute("id")
 objAttrib.text = "https://api.constantcontact.com/ws/customers/" & UN & "/lists/5"
 ContactList.setAttributeNode objAttrib
 ContactLists.appendChild ContactList
 
  server.MapPath("App_Data\MyXMLDoc.xml")

Open in new window

0
 
Evan CutlerAuthor Commented:
Paul,
Thanks for the info.  Does this remove the "xmlns" from the child entries?
<summary xmlns="" type="text">Contact</summary>
  <content xmlns="" type="application/vnd.ctct+xml">


I don't want them there.  I only want them in specific tags.
0
 
PaulHewsCommented:
Yes
0
 
Evan CutlerAuthor Commented:
YOU ARE AWESOME!!!!

Thank you so much...That worked perfectly.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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