Return-Path: X-Original-To: apmail-commons-user-archive@www.apache.org Delivered-To: apmail-commons-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6791018D99 for ; Wed, 25 Nov 2015 20:51:15 +0000 (UTC) Received: (qmail 72580 invoked by uid 500); 25 Nov 2015 20:51:14 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 72464 invoked by uid 500); 25 Nov 2015 20:51:14 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 72453 invoked by uid 99); 25 Nov 2015 20:51:14 -0000 Received: from Unknown (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 25 Nov 2015 20:51:14 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 13F14C0845 for ; Wed, 25 Nov 2015 20:51:14 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.8 X-Spam-Level: * X-Spam-Status: No, score=1.8 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_MSPIKE_H2=-0.001, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id wekt6Xq9UMsO for ; Wed, 25 Nov 2015 20:51:06 +0000 (UTC) Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.126.131]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with ESMTPS id 031FB428FF for ; Wed, 25 Nov 2015 20:51:05 +0000 (UTC) Received: from [192.168.178.20] ([94.217.137.75]) by mrelayeu.kundenserver.de (mreue004) with ESMTPSA (Nemesis) id 0LkUgR-1acwSJ1sRn-00cR2F for ; Wed, 25 Nov 2015 21:51:04 +0100 Subject: Re: Fwd: Parse XML configuration file with namespaces To: Commons Users List References: <5654C80B.90109@oliver-heger.de> From: Oliver Heger Message-ID: <56561F39.9010103@oliver-heger.de> Date: Wed, 25 Nov 2015 21:51:05 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:0Tg4FpE/Wf/6r6CFizWhjdgHyQYFezFz1L2lEmO8sHOHT3dNh0q 2iA9CKQHrhKLkdo6kIscUJhjalwfK07tFyDOW5aSDEKGEP9VcmuN9ZfzraCLo4IEtKkqy3e HnvxbOAOZQpkUSlWM7m46PSymbSoEGFKl9cNh4o1iUg77K6glCztBBm50SnzW70SxtBmfHD MBBdGWxCtaATlEIpFpA9Q== X-UI-Out-Filterresults: notjunk:1;V01:K0:VVa5D1lTNCo=:sNryElZ6po1Z1d5u7S/BAl yYtgtl/A7Rke6MGAvpHCBGoHbjPepQUM00bdbagA7x1iILkaZoDCzirdBd6bVZhXqS5vkhci8 5bj5ckeYn67Yiykf+54TQkaZTq8HZahxnmg9dtd4pVz94HUOeXrxtbIPLdP9OVqAZw8GgF7Sq wb4Xm1vFCkd2O/ukOiV1Rp6Om7xlFXm6E7fMX/A2Dpju3YHwDNaargWsFE2n2x1GxlAndvGxN 52M8sPo/7Ad1ZQDoKO/13z1vXxBfvftICdSlPY7LcVKXWK7A/xhlTc4ewt24Klbm+HDVvCXXQ Dnrc1Nm4vKV4GbK0kn7/2UH+FnIfTAeG6L3xP1tXUrHJQiP3wmUBB8+cPT25v+R0AVNrabyxs rWK8pw2czi4HAM3TTZUFfQ5ZWo+gGwWvrO/Iebo0YEdCtIsMXqCR9mtrd0gQN/fKxlOY2Ugx2 nW7hO1eaS9YspNH5XZHsHRVveqeumEsVP9GDwwPWs2lNG6qlXQWzzjAkOROquXRHAuObqKQHt mIseG4aVg35MBRfX70kNHG/OHn27/63bZlNm1qYsffrDFb3lko7NQrQSGTuuE3rh2Rn7RuRXz cGaoXg15WNB8zzcgqURSo50IvLLTFUGPOGr2h7XtWQ86wi2LI7qWICF/dP4dEQLwR6neS+Sgb Xd3TfDSGpKKf6c6dWo+oL9kQbKccI9+cQ/fuIUc/X+Zz9Y87yoyyk0XZVok65jfb1OMRmoQjX Cr6A5e5GhXKzu4Mt Hi Maurizio, you are probably affected by this bug: https://issues.apache.org/jira/browse/CONFIGURATION-573 It has been fixed for the upcoming 2.0 release, but is not available for Configuration 1.10. I fear, you will have to use the default expression engine for the time being :-( Oliver Am 25.11.2015 um 09:37 schrieb Maurizio Lattuada: > Hi @all, > > > @Siegfried: all my XSD files are stored locally. In fact, when I call > the "load()" method (setSchemaValidation is true), the XML is loaded > correctly. By the way, I introduced on purpose some errors in the XML > file and it was not correctly loaded, meaning that the validation is > really active and working (so, XSD files are correctly found). > > @Oliver: thanks for the hint, but I think there is a strange behavior > in my opinion. > > Iterator it = xmlPersonConfiguration.getKeys(); > while (it.hasNext()) { > LOGGER.info(it.next()); > } > final String string = namespace + Tags.PERSON; // namespace is a > parameter equals to "p:" > xmlPerson = xmlPersonConfiguration.configurationsAt(string); > LOGGER.info("--> Found " + xmlPerson.size() + " persons (key: " + > string + ")"); > > This lead to have: > 2015-11-25 09:08:10,320 [c.v.t.b.r.ConfigReader:402 ] INFO - > parsePerson : p:person/p:title > 2015-11-25 09:08:10,324 [c.v.t.b.r.ConfigReader:402 ] INFO - > parsePerson : p:person/p:firstName > 2015-11-25 09:08:10,326 [c.v.t.b.r.ConfigReader:402 ] INFO - > parsePerson : p:person/p:lastName > ...all the tags here are correctly logged... > 2015-11-25 09:08:10,346 [c.v.t.b.r.ConfigReader:402 ] INFO - > parsePerson : @xmlns:ath > 2015-11-25 09:08:10,346 [c.v.t.b.r.ConfigReader:402 ] INFO - > parsePerson : @xmlns:com > 2015-11-25 09:08:10,346 [c.v.t.b.r.ConfigReader:402 ] INFO - > parsePerson : @xmlns:p > 2015-11-25 09:08:10,347 [c.v.t.b.r.ConfigReader:402 ] INFO - > parsePerson : @xmlns:xsi > 2015-11-25 09:08:10,347 [c.v.t.b.r.ConfigReader:402 ] INFO - > parsePerson : @xsi:schemaLocation > 2015-11-25 09:08:10,720 [c.v.t.b.r.ConfigReader:406 ] INFO - > parsePerson : --> Found 0 persons (key: p:person) > > Question: since my xml file has this structure (I omit the namespace > declaration for ease of reading): > > > ... > ... > > > ... > ... > > > > Why "p:person" is not in the keys, but only the sub-tags of p:person? > When I had my xml with the XSD, but without namespaces, looking for > "person" worked fine, so I was able to iterate on the 2 persons > available in the XML example above. > > By the way, I also tried to look for "p:person/p:title", that is a key > found by calling the "getKeys()" method: > xmlPerson = xmlPersonConfiguration.configurationsAt("p:person/p:title"); > LOGGER.info("--> Found " + xmlPerson.size() + " persons"); > > but the xmlPerson.size is always equal to 0. > FYI xmlPersonConfiguration is created and initialized as: > > XMLConfiguration xmlPersonConfiguration = new XMLConfiguration(); > xmlPersonConfiguration.setExpressionEngine(new > XPathExpressionEngine()); > xmlPersonConfiguration.setSchemaValidation(true); > xmlPersonConfiguration.setFileName("..."); > xmlPersonConfiguration.load(); > > If I don't call the "setExpressionEngine" method and I search for tags > like "p:person.p:title" or "p:person", all these entries are correctly > found and I can iterate over them. > > Any other suggestions? > > > thanks in advance for the feedback. > > 2015-11-24 21:26 GMT+01:00 Oliver Heger : >> Hi Maurizio, >> >> in order to debug your problem, you can call the configuration's >> getKeys() method. From the iterator returned you should see the >> available keys. These keys can then also be used for querying properties. >> >> HTH >> Oliver >> >> Am 24.11.2015 um 13:54 schrieb Maurizio Lattuada: >>> 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: >>> >>> >>> >> 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 "> >>> >>> Dr. >>> ... >>> >>> >>> Mr. >>> ... >>> >>> >>> >>> This is an extract of the persons.xsd, as you can see there are a >>> couple of imports >>> >>> >> xmlns:common="tdm:configuration:common" >>> xmlns:authentication="tdm:configuration:authentication" >>> targetNamespace="tdm:configuration:entities" >>> xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> >>> >> namespace="tdm:configuration:common" /> >>> >> namespace="tdm:configuration:authentication" /> >>> .... >>> >>> >>> >>> 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 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 >> > > > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@commons.apache.org For additional commands, e-mail: user-help@commons.apache.org