views:

127

answers:

2

Application1 has a xml configuration file say:

<Application1>
   <ConfigApp1>Value1</ConfigApp1>
   <App1Layout>Layout</App1Layout>
</Application1>

Application2 has a xml configuration file say:

<Application2>
   <ConfigApp2>Value2</ConfigApp2>
   <App2Layout>Layout</App2Layout>
   </Options>Others</Options>
</Application2>

I want to have a common configuration file for my application which is as such:

<MyApplication>
<MyAppConfiguration>Configuration</MyAppConfiguration>
<Application1>
   <ConfigApp1>Value1</ConfigApp1>
   <App1Layout>Layout</App1Layout>
</Application1>
<Application2>
   <ConfigApp2>Value2</ConfigApp2>
   <App2Layout>Layout</App2Layout>
   </Options>Others</Options>
</Application2>
</MyApplication>

and applications Application1 and Application2 should be able to configure themselves from this same configuration file.

As far as i know this is not possible as Application1/Application2 will see the start and end tag of MyApp Configuration file to MyApplication and discard it saying - invalid configuration file.

Is there any way to achieve the same without modifying application1/application2?

+1  A: 

You can use XSLT to merge the two XML documents. You can find an example script here.

I think you misunderstood my question or I could not follow you. There are two application specific configuration files. I want to merge them and still both the applications should be able to consume them.
Devil Jin
A: 

If you can modify those two applications to use your new file (which, depending on the way they process their configuration may or may not be very straightforward) then do so. Otherwise I wouldn't bother - you'd just be creating problems for yourself with no real benefit.

That said, if it's acceptable to you to have some intermediary step (which is what trippy was alluding to if I've understood correctly), you can have a single "source" XML configuration file that you will then process (via XSLT or otherwise) to derive 2 separate configuration files from that will be then read by your applications.

ChssPly76