wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes Splitting an XML file 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 "Splitting an XML file" Watch "Splitting an XML file" New topic
Author

Splitting an XML file

vasu maj
Ranch Hand

Joined: Jul 12, 2001
Posts: 395
I have an xml file for look up of datasources. It has all the necessary entries for each of its datasources. How can I split this into two files and keep only login details in a separate file and access those from this file? How do I refernce only those two properties of user name and password which are in the second file from the first file?


Thanks,

Vasu


What a wonderful world!
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
What you wanna use DOM or XSLT ?


Spritle Software Blogs
vasu maj
Ranch Hand

Joined: Jul 12, 2001
Posts: 395
This is the entry of a datasource in the xml file. Now I want the user name and password propeties to be taken out of this file, put in another file which is more secure and acess those parameters from this file.



Thanks,

Vasu
[ October 27, 2004: Message edited by: vasu maj ]
vasu maj
Ranch Hand

Joined: Jul 12, 2001
Posts: 395
Well? Nobody has done anything like this before?
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
You could use XML entities to read the username and password from a separate file a bit like this. It would, however, require you to put the username and password into separate files unless you'd decide to externalize the whole
    <parameter>
        <name>username</name>
        <value>user</value>
    </parameter>
    <parameter>
        <name>password</name>
        <value>password</value>
    </parameter>
into an external file and include that inside the <Resource/> element

Another option could be to generate the resulting configuration file with XSLT and using the document() function and XPath to locate the username and password for each DataSource. This would allow placing all DataSource usernames/passwords into a single file but would also add complexity into the whole setup since you're not dealing with "static" files anymore but using XSL transformation instead.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
vasu maj
Ranch Hand

Joined: Jul 12, 2001
Posts: 395
Thanks but I didn't understand why I can't put two properties ( username and password) into one file and include the file. Also how are the properties read if some properties of the same datasource are in the original file and others are in a different file? Do I need to define a resource with the same names as in the original file with only the two properties in the included file?


Thanks
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Originally posted by vasu maj:
Thanks but I didn't understand why I can't put two properties ( username and password) into one file and include the file.

This is what Lasse explained you how to do it.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by vasu maj:
Thanks but I didn't understand why I can't put two properties ( username and password) into one file and include the file.

Because the XML entity inclusion method includes the whole contents of the referred file, not just parts of it.

In other words, you'd need to have these 3 files:
datasource-username.txt
datasource-password.txt
datasource.xml

with the following contents:

datasource-username.txt

datasource-password.txt

datasource.xml


This XML document, when parsed by an XML parser, would be equivalent to the following document:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Splitting an XML file
 
Similar Threads
Jakarta commons Digester
reg: datasource - very very urgent
Binding DataSource with JBoss
How to get connected to 2 databases
Server Design