commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Dorsey <>
Subject RE: [configuration] XML fragments
Date Wed, 16 Nov 2011 14:21:17 GMT
I see that you have said that there is no root element, but if you have an automated process
that concatenates the xml docs together then what is the blacking factor to having the last
step of that process create an arbitrary root tag then using something like the following
to parse the parts that you need?

		NodeList tempList;
		Node tempNode;
		File fXmlFile = new File(docName);
		DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
		DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
		Document doc = dBuilder.parse(fXmlFile);
		tempList = doc.getElementsByTagName("[node that you specify]");

Then you use getFirstChil(), getNextSibling() and getNodeValue() to grab the data that you
require. I agree that it is not ideal, but I have used it on occasion.

Jason Dorsey | Engineering Intern

-----Original Message-----
From: Emmanuel Bourg [] 
Sent: Tuesday, November 15, 2011 2:51 AM
To: Commons Users List
Subject: Re: [configuration] XML fragments

Hi Billy,

Such a file can't be parsed in Java since it's not well formed. You can 
try to add a root element when the files are concatenated to work around 
this issue.

Emmanuel Bourg

Le 15/11/2011 05:12, Billy Newman a écrit :
> Does the configuration API support XML fragments?
> I have a situation in which I have many XML files that I concatenate
> together.  Because I do this there is no root element.
> <node>
> ....
> </node>
> <node>
> ...
> </node>
> I have tried but get an error that there is no root element.
> I am using the configuration builder class to read in an XML file that
> specifies my configuration. Maybe there is a way to add a root element
> in the XML tag.
> Confit
> <xml fileName="nodes.xml .......
> Thanks
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message