• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can I include a .xml file within another?

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic