Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

VBScript to XML problem

Posted on 2010-01-03
4
Medium Priority
?
485 Views
Last Modified: 2012-05-08
Greetings EE Gods...

The attached code brings on the below output.
whenever I remove the ":cc", the "xmlns" populates all child nodes.
I cannot have either.  how do I manipulate the code where I don't have to use namespaces, and still only have the attributes where I need them.

thanks

<entry xmlns:cc="http://www.w3.org/2005/Atom">
<title type="text"/>
<author/>
<id>data:,none</id>
<summary type="text">Contact</summary>
<content type="application/vnd.ctct+xml">
<contact xmlns:cc="http://ws.constantcontact.com/ns/1.0/">
<EmailAddress>abc@yahoo.com</EmailAddress>
<Name>John Smith</Name>
<OptInSource>ACTION_BY_CUSTOMER</OptInSource>
<ContactLists>
<ContactList id="http://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 objChild = objDom.createElement("title")
 Set objAttrib = objDom.createAttribute("type")
 objAttrib.text = "text"
 objChild.setAttributeNode objAttrib
 objRoot.appendChild objChild
 
 Set objChild = objDom.createElement("updated")
 objChild.text = Date()
 objRoot.appendChild objChild

 Set objChild = objDom.createElement("author")
 objRoot.appendChild objChild
 
 Set objChild = objDom.createElement("id")
 objChild.text = "data:,none"
 objRoot.appendChild objChild

 Set objChild = objDom.createElement("summary")
 Set objAttrib = objDom.createAttribute("type")
 objAttrib.text = "text"
 objChild.setAttributeNode objAttrib
 objChild.text = "Contact"
 objRoot.appendChild objChild
 
 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:cc")
 objAttrib.text = "http://ws.constantcontact.com/ns/1.0/"
 contact.setAttributeNode objAttrib
 content.appendChild contact

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

 Set contactinfo = objDom.createElement("OptInSource")
 contactinfo.text = "ACTION_BY_CUSTOMER"
 Set objAttrib = Nothing
 contact.appendChild contactinfo
 
 Dim ContactLists
 Set ContactLists = objDom.createElement("ContactLists")
 Set objAttrib = Nothing
 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
 


  'Set objPI = objDom.createProcessingInstruction("xml","version='1.0'")
  'objDom.insertBefore objPI, objDom.childNodes(0)
  objDom.Save server.MapPath("App_Data\MyXMLDoc.xml")

Open in new window

0
Comment
Question by:Evan Cutler
  • 3
4 Comments
 
LVL 22

Accepted Solution

by:
neeraj523 earned 1000 total points
ID: 26168633
hello

Not sure if i understood your question clearly.. But try this if it solves your problem..


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 objChild = objDom.createElement("title")
 Set objAttrib = objDom.createAttribute("type")
 objAttrib.text = "text"
 objChild.setAttributeNode objAttrib
 objRoot.appendChild objChild
 
 Set objChild = objDom.createElement("updated")
 objChild.text = Date()
 objRoot.appendChild objChild

 Set objChild = objDom.createElement("author")
 objRoot.appendChild objChild
 
 Set objChild = objDom.createElement("id")
 objChild.text = "data:,none"
 objRoot.appendChild objChild

 Set objChild = objDom.createElement("summary")
 Set objAttrib = objDom.createAttribute("type")
 objAttrib.text = "text"
 objChild.setAttributeNode objAttrib
 objChild.text = "Contact"
 objRoot.appendChild objChild
 
 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:cc")
// objAttrib.text = "http://ws.constantcontact.com/ns/1.0/"
// contact.setAttributeNode objAttrib
 content.appendChild contact

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

 Set contactinfo = objDom.createElement("OptInSource")
 contactinfo.text = "ACTION_BY_CUSTOMER"
 Set objAttrib = Nothing
 contact.appendChild contactinfo
 
 Dim ContactLists
 Set ContactLists = objDom.createElement("ContactLists")
 Set objAttrib = Nothing
 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
 


  'Set objPI = objDom.createProcessingInstruction("xml","version='1.0'")
  'objDom.insertBefore objPI, objDom.childNodes(0)
  objDom.Save server.MapPath("App_Data\MyXMLDoc.xml")

Open in new window

0
 
LVL 9

Author Comment

by:Evan Cutler
ID: 26172860
no,
I'm sorry...
I need the attributes:
Set objAttrib = objDom.createAttribute("xmlns:cc")
is a valid line.

However, from what I have now, if I don't set namespace on the attribute (":cc"), then the attribute populates all the child nodes underneath.

I need my cake and be able to eat it to:
It needs to look like this, without the child nodes being populated the same way:
Set objAttrib = objDom.createAttribute("xmlns")

Thanks.
0
 
LVL 9

Author Comment

by:Evan Cutler
ID: 26177716
Below is the output of what I'm talking about.
if I remove the ".cc",  this is what's shown.

I only want xmlns to be in the entry tag, and the contact tag.

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>
0
 
LVL 9

Author Closing Comment

by:Evan Cutler
ID: 31672229
Thank you so much for the effort, but this is not what I'm looking for.

I see it as my fault.  I am reformatting the question and asking a better one.  I can tell you answered exactly what I was asking.

Thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question