Solved

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

Posted on 2014-04-21
1
576 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
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Error opening .xml with Excel 2013 4 19
jaxb jaxp sax dom 7 43
D3, SVG, dragging a star. 2 109
VB.Net and XML XSD Files 1 43
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now