You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Billy Newman <ne...@gmail.com> on 2011/11/15 05:12:15 UTC
[configuration] XML fragments
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: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
RE: [configuration] XML fragments
Posted by Jason Dorsey <Ja...@netiq.com>.
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);
doc.getDocumentElement().normalize();
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 [mailto:ebourg@apache.org]
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: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re: [configuration] XML fragments
Posted by Emmanuel Bourg <eb...@apache.org>.
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: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>