How to split one XML into smaller XML; received via a XMLHttpRequest?

N

NorbertH

Hi!

After sending a request to a server via XMLHttpRequest and receiving a
response, I assign an incoming XML from a server via
[...]
var root = request.responseXML.documentElement;
[...]
to the variable root which I process further with root.nodeType,
root.nodeValue, etc...

In my example I have the following XML File:
<activities>
<day date="20061001">
<activity>I did this</activity>
<activity>I did that</activity)
</day>
<day date="20061002">
<activity>I was doing this</activity>
<activity>And this</activity>
<activity>And that</activity>
</day>
<day date="20061003">
<activity>and so on</activity>
</day>
</activities>

Now here is my question: How can I assign the big XML (root:
activities) into e.g. three smaller XML's (with the new root: day) to
an array?

Thanks,

Norbert
 
C

Chad.Burggraf

<activities>
<day date="20061001">
<activity>I did this</activity>
<activity>I did that</activity)
</day>
<day date="20061002">
<activity>I was doing this</activity>
<activity>And this</activity>
<activity>And that</activity>
</day>
<day date="20061003">
<activity>and so on</activity>
</day>
</activities>

Now here is my question: How can I assign the big XML (root:
activities) into e.g. three smaller XML's (with the new root: day) to
an array?

var days = root.getElementsByTagName("day");

days will now be an array of "day" nodes. You could also use XPath, but
of course IE doesn't support the DOM Level 3 XPath standard, so you'll
have to do some feature detection. In this simple case
getElementsByTagName would suffice.

Cheers
Chad
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top