File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes Can I include a .xml file within another? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Can I include a .xml file within another?" Watch "Can I include a .xml file within another?" New topic
Author

Can I include a .xml file within another?

Jeya Balaji
Ranch Hand

Joined: Jan 02, 2003
Posts: 40
Hello all,
I want to define some context param. Instead of cluttering web.xml, I would like to place all the init param in another file, say properties.xml and include this file in web.xml
Is this possible? If so, please help with the include syntax.
Regards,
Balaji


Regards, Balaji
Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
Yes, you can use parsed external entity to include extra xml fragment into your xml. The entire well-formed XML file can be included too, but without xml decl!
Jeya Balaji
Ranch Hand

Joined: Jan 02, 2003
Posts: 40
Hi Roseanne,
Thanks for the lead.
I read the related doc at http://www.w3.org/TR/xml-fragment
This is didnot help my purpose because fragments seems to attach different files and generate something new with .fcs (which the application should be aware of handling).
I want to include a xml file into web.xml
(something like jsp's way of including other files <jsp:include page='file'>
After searching in the saloon, I found the following section useful :


This inclusion worked well for a simple document like this.
However, I couldn't use this method with web.xml because it already has DOCTYPE
I am downloading the jsp and servlet spec from sun.com - to read more about web.xml standards and a way to include another file.
If anyone had done this kind of include, please help me with the syntax.
Regards,
Balaji
Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
Sorry, I answered the question in a hurry, and did not put on the details. I put the detail on the web, but forgot coming back to give you a link.
The one you put here is exactly what I meant, using parsed external entities. This is almost the de facto way used in ant build.xml, which enables different projects share the common settings as well as common ant targets. The FAQ I put on the web for your question has example in it. It is tested and valid. It may also solve that web.xml already has DOCTYPE problem. Take a look here:
Q. Can I include an xml file within another?
Jeya Balaji
Ranch Hand

Joined: Jan 02, 2003
Posts: 40
Thanks, Roseanne. I am able to include the file after couple of juggling with the entity item.
Your website looks nice. I tried clicking on couple of projects at allinone.jsp, but got null pointer exception.
btw, I would like to know the job market in China (seeing the site, I guess you are from China).
This is a deviation from the main topic; please feel free to skip ...
Six months back, I got a job offer from a software company in ShenZhen. If everything had gone good, I am supposed to work there by December. I guess due to bad market, the employer couldn't send me the papers. I had asked him couple of times and he is just asking me to wait.
If u have time, can u tell me the market situation there? Like, are there growth, new companies starting or mnc opening branches ...
Thanks for your help.
Regards,
Balaji
Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
ShenZhen is one of the most developed areas in China. Job market in China is much better than US right now. However, I don't know the details, since I'm living the US.
Good luck on your job offer, hope you have a chance to work in ShenZhen, Guangdong, China.
Jeya Balaji
Ranch Hand

Joined: Jan 02, 2003
Posts: 40
Thanks for the comments, Roseanne.
I still have problem with the xml include.
Your suggestion worked with web.xml when I view it in IE. IE was able to pick myfrag.xml from the same dir where web.xml is placed.
But tomcat failed to locate the file. I got the error :
Resolve entity failednull file:///D:/webtools/tomcat/bin/myfrag.xml
Here is the portion of web.xml


This works with IE but doesn't work for Tomcat.
I tried placing PUBLIC instead of SYSTEM. For which, I got the error :
Resolve entity failedmyfrag.xml file:///D:/webtools/tomcat/bin/myfrag.xml

Will look for more combinations, if it doesn't work, I guess I will have to place all the initializing variables in web.xml itself instead of a seperate file.
Thanks for your time.
Regards,
Balaji
Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
Of course, hard coded dtd path or xml path will not work on tomcat! See here
http://bobcat.webappcabaret.net/javachina/faq/tomcathowto.htm#tfaq_05
However, the above answer does work for loading web.xml. The only thing I can think of my head is putting the included file in the same directory as web.xml. Try it to see if it works. Let us know. I've never done this...
Jeya Balaji
Ranch Hand

Joined: Jan 02, 2003
Posts: 40
Thanks a lot for your time.
I forgot to mention that the xml file is located in the same dir as web.xml
I followed the link you gave and found the java code. However, in this problem, we need a similar mechanism in xml ...
Let us c.
Regards,
Balaji
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can I include a .xml file within another?