commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Siegfried Goeschl <siegfried.goes...@it20one.com>
Subject Re: Parse XML configuration file with namespaces
Date Tue, 24 Nov 2015 17:38:22 GMT
Hi Maurizio,

I never used commons-configuration and this could be utterly wrong but could it be related
that the XML parser can’t download/find your XSDs?  

Cheers,

Siegfried Goeschl

> On 24 Nov 2015, at 13:54, Maurizio Lattuada <maurizio.lattuada@gmail.com> wrote:
> 
> Hi guys,
> 
> I'm dealing with a strange problem while parsing an XML file (with
> namespaces) using commons configuration 1.10.
> First of all, let me say that when I call the "load()" method on the
> following XML file (validation is active), it is loaded flawless.
> 
> This is an extract of the xml to be parsed:
> <!-- persons.xml-->
> <?xml version="1.0" encoding="UTF-8"?>
> <p:persons
>    action="create"
>    xmlns:ath="tdm:configuration:authentication"
>    xmlns:com="tdm:configuration:common"
>    xmlns:p="tdm:configuration:entities"
>    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>    xsi:schemaLocation="tdm:configuration:entities ../xsd/model/persons.xsd ">
>    <p:person>
>        <p:title>Dr.</p:title>
>        ...
>    </p:person>
>    <p:person>
>        <p:title>Mr.</p:title>
>        ...
>    </p:person>
> </p:person>
> 
> This is an extract of the persons.xsd, as you can see there are a
> couple of imports
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns="tdm:configuration:entities"
> xmlns:common="tdm:configuration:common"
>    xmlns:authentication="tdm:configuration:authentication"
> targetNamespace="tdm:configuration:entities"
>    xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
>    <xs:import schemaLocation="../namespace/common.xsd"
> namespace="tdm:configuration:common" />
>    <xs:import schemaLocation="auth_mean.xsd"
> namespace="tdm:configuration:authentication" />
>    ....
> </xs:schema>
> 
> 
> And finally an extract of the code to setup the parse and to read the document:
> XMLConfiguration xmlPersonConfiguration = new XMLConfiguration();
> xmlPersonConfiguration.setDelimiterParsingDisabled(true); // needed
> because I've attribute with multiple values like "a,b,c"
> xmlPersonConfiguration.setExpressionEngine(new XPathExpressionEngine());
> xmlPersonConfiguration.setSchemaValidation(true);
> xmlPersonConfiguration.setFileName("persons.xml");
> xmlPersonConfiguration.load();
> List<HierarchicalConfiguration> xmlPersons;
> xmlPersons = xmlPersonConfiguration.configurationsAt("person");
> 
> Shortly, either I try to search for (last statement):
> * person
> * p:person
> * //person
> * //p:person
> * /p:persons/p:person
> *...
> 
> No elements are found.
> According to the commons configuration documentation, "The XML Parser
> will then use the schema defined in the XML document to validate it.
> Enabling schema validation will also enable the parser's namespace
> support.".
> Please note: before I had such xml and xsd files without namespaces
> and everything worked fine.
> 
> I'm pretty sure I'm doing something wrong, but I can't figure what.
> Any idea about this behavior?
> 
> Thanks for your kind feedback
> 
> --
> Maurizio Lattuada
> 
> ---------------------------------------------------------------------
> 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


Mime
View raw message