permaculture playing cards*
The moose likes XML and Related Technologies and the fly likes importing one xml in another Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "importing one xml in another" Watch "importing one xml in another" New topic
Author

importing one xml in another

D Preethi
Ranch Hand

Joined: May 24, 2008
Posts: 68
Hi All,

Can someone indicate how to exactly import one xml file in another xml file?


Thanks in advance,
Preethi
Chinna Eranna
Ranch Hand

Joined: Dec 08, 2009
Posts: 174

What do you mean by "Importing an xml into another".

Xml is just a structure rather a language.


- Chinna
D Preethi
Ranch Hand

Joined: May 24, 2008
Posts: 68
I mean, something like, if there are number of small xml files, is there a way I can create one parent xml file which can make use of these files directly? Something like, "import" in Java?
Chinna Eranna
Ranch Hand

Joined: Dec 08, 2009
Posts: 174

You can do that.. by introducing a new tag for import of xml's.

Something like..

<Root>
<ChildXml>myChild.xml</ChildXml>
</Root>

Also.. your xml parser should be intelligent enough to identify these.. and take required actions.
D Preethi
Ranch Hand

Joined: May 24, 2008
Posts: 68
Thanks. Can you please point me to some example where there is import of xmls?
Chinna Eranna
Ranch Hand

Joined: Dec 08, 2009
Posts: 174

We have used a similar example.. I shown above in one of our app.

You can also refer an example here..

http://www.xml.com/pub/a/2002/07/31/xinclude.html
D Preethi
Ranch Hand

Joined: May 24, 2008
Posts: 68
Actually, I looked into those examples but they don't seem to work for me. Can you please point out my mistake? test1.xml and test2.xml look like this:





When I open test1.xml, it just shows -
The Wit and Wisdom of George W. Bush

I have placed both test1.xml and test2.xml in same location. Any idea what I am doing wrong ?
Chinna Eranna
Ranch Hand

Joined: Dec 08, 2009
Posts: 174

Thats what I mean to say..

"Your xml parser should be intelligent enough to identify these"
pete reisinger
Ranch Hand

Joined: Dec 30, 2009
Posts: 46
D Preethi wrote:Hi All,

Can someone indicate how to exactly import one xml file in another xml file?


Thanks in advance,
Preethi


Hi, I was trying to do the same thing once, first I inserted placeholder in the first xml and then replaced the placeholder with another xml.
But I didn't like it. So after some searching I've done this (it takes to xml strings - envelope and body, and inserts body inside the envelope's <Body></Body> tags):


The code should be self explanatory, but if anything is unclear, or somebody knows how to do it another way (better, easier) let us know.
D Preethi
Ranch Hand

Joined: May 24, 2008
Posts: 68
Thanks Pete.

So, without using the includes tag, there is no way to do the import of the xml files in other xml files, right? XML doesn't support that kind of feature automatically (or by just using entity references) ?



- Preethi

pete reisinger
Ranch Hand

Joined: Dec 30, 2009
Posts: 46
Hi,
what do you mean without using the import tags? In my example you have to xml documents the and only thing you need to know is where you want to insert the second xml file. You can easily change it and insert the second file inside the root tag of the first one etc.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: importing one xml in another