Solved

vb script/classic asp:  append xml documents to node of another xml document

Posted on 2014-04-21
1
594 Views
Last Modified: 2014-04-22
In vb script / classic asp, How do I make it so I can append xml documents that are in an array to another xml Document as follows:

Set xmlDoc = CreateObject("Microsoft.XMLDOM")  
Set objRoot =  xmlDoc.createElement("runners")  :xmlDoc.appendChild objRoot  

Set objIntro =   xmlDoc.createProcessingInstruction ("xml","version='1.0'")  
xmlDoc.insertBefore objIntro,xmlDoc.childNodes(0)


for c__ = 1 to ubound(c_)
        'xarray is an array of xmldom documents
      objroot.appendchild xarray(c__)

next

This currently errs
0
Comment
Question by:KeithMcElroy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 40014272
Here is some code I tested in VBA (because it's easier to debug than classic ASP).

Note that to me this doesn't make much sense without knowing what's in your arrays so I assumed they are the same length and there's nothing in array element 0 (looking at your for-loop code).
Dim c_(2), xarray(2)
Set xarray(1) = CreateObject("Microsoft.XMLDOM")
xarray(1).LoadXML "<root1><testdata1/></root1>"
Set xarray(2) = CreateObject("Microsoft.XMLDOM")
xarray(2).LoadXML "<root2><testdata2/></root2>"

Set xmldoc = CreateObject("Microsoft.XMLDOM")
Set objroot = xmldoc.createElement("runners"): xmldoc.appendchild objroot

Set objIntro = xmldoc.createProcessingInstruction("xml", "version='1.0'")
xmldoc.InsertBefore objIntro, xmldoc.ChildNodes(0)


For c__ = 1 To UBound(c_)
        'xarray is an array of xmldom documents
      objroot.appendchild xarray(c__).DocumentElement

Next

Open in new window

*edit: note the added ".DocumentElement"

result:
<?xml version="1.0"?>
<runners><root1><testdata1/></root1><root2><testdata2/></root2></runners>

Open in new window

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

710 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