473,327 Members | 2,094 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

DOM importNode

Hey everyone,

I am trying to figure out how to import an external xml file into a
current document at a certain location within the document ie:

Here is my main xml:

<books>
<book>
<title>1</title>
<author>a</author>
</book>
<book>
<title>2</title>
<author>b</author>
</book>
<book>
<title>3</title>
<author>c</author>
</book>
</book>
And here is the xml to be imported:

<book>
<title>new</title>
<author>new author</author>
</book>

I would like to import this right after the first book entry (after 1,
before 2), can anyone point me in the right direction here?

Thanks!

Ben

Oct 11 '06 #1
2 1979

"uidzer0" <be************@gmail.comwrote in message
news:11**********************@m7g2000cwm.googlegro ups.com...
Hey everyone,

I am trying to figure out how to import an external xml file into a
current document at a certain location within the document ie:

Here is my main xml:

<books>
<book>
<title>1</title>
<author>a</author>
</book>
<book>
<title>2</title>
<author>b</author>
</book>
<book>
<title>3</title>
<author>c</author>
</book>
</book>
And here is the xml to be imported:

<book>
<title>new</title>
<author>new author</author>
</book>

I would like to import this right after the first book entry (after 1,
before 2), can anyone point me in the right direction here?

Thanks!

Ben
since you are asing in a php group, and it's such a basic question (I must
be reading what you want wrong or something), how about:

# file import.xml
<book>
<title>new</title>
<author>new author</author>
</book>

# file base_xml.php
<books>
<book>
<title>1</title>
<author>a</author>
</book>
<?php include ("import.xml"); ?>
<book>
<title>2</title>
<author>b</author>
</book>
<book>
<title>3</title>
<author>c</author>
</book>
</book>

Oct 11 '06 #2
uidzer0 wrote:
Hey everyone,

I am trying to figure out how to import an external xml file into a
current document at a certain location within the document ie:

Here is my main xml:

<books>
<book>
<title>1</title>
<author>a</author>
</book>
<book>
<title>2</title>
<author>b</author>
</book>
<book>
<title>3</title>
<author>c</author>
</book>
</book>
And here is the xml to be imported:

<book>
<title>new</title>
<author>new author</author>
</book>

I would like to import this right after the first book entry (after 1,
before 2), can anyone point me in the right direction here?

Thanks!

Ben
Are you using DOM for this? If so,

$doc1 = new DOMDocument("main.xml");
$doc2 = new DOMDocument("new.xml");

$newBook = $doc1->importNode($doc2->documentElement, true);
$doc1->documentElement->insertBefore($newBook,
$doc1->documentElement->childNodes->item(2));
That oughtta do it. http://www.php.net/dom for more info.

Jeremy
Oct 11 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Andy Fish | last post by:
Hi, I have server-based Java application that maintains a fairly large XML structure as a DOM. In response to a user request I want to select various nodes (including sub-nodes) and jam them...
1
by: Andrew Jacobs | last post by:
I am using C# to write an application that migrates documents from one version of an XML schema/DTD to later one. Much of the document has the same structure in the two versions and I use...
1
by: Peter Nofelt | last post by:
Hey All, I'm running into this issue with parsing through an xml document by tag name. Below is an example xml document: File Name: things.xml <things> <people> <name>Peter</name>
5
by: yawnmoth | last post by:
I wrote the following in an attempt ot better understand importNode: <script> f1=document.createElement("iframe"); f1.src=unescape("http://www.domain.tld/test.txt");...
3
by: polism | last post by:
Hi, I have the following simple code, using xerces running on my windows. This demo compiles and runs normally, but when I open my Task Manager, I see a constant memory growth of my process, and I...
10
by: Simon Brooke | last post by:
The DOM API has included public Node importNode(Node,boolean) as a method of the Document interface for a long time. Does anything actually implement it? Xerces 2 is giving me: ...
5
by: luthriaajay | last post by:
An extremely tricky and challenging code. I have been able to add 2 XML documents together using importNode(). xmlDoc1 ----------
0
by: luthriaajay | last post by:
An extremely tricky and challenging code. I have been able to add 2 XML documents together using importNode(). xmlDoc1 ---------- <?xml version="1.0" encoding="UTF-8"?>
11
by: =?ISO-8859-1?Q?Une_B=E9v?==?ISO-8859-1?Q?ue?= | last post by:
at the page : <http://thoraval.yvon.free.fr/Fixed_layout/import_nodes.xhtml> when importing an svg document i have to do : document.importNode(...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.