How to use xi include and fallback
2010-11-08 00:50:09 GMT
<xi:fallback>
</xi:fallback>
</abc>
dbf.setNamespaceAware(true);
dbf.setXIncludeAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse("mainxml.xml");
Hi Peter,
The fallback is only used in the event of a resource error [1]. For example, the file doesn't exist or possibly there's some kind of connection problem which prevents the parser from accessing the URI (specified as the value of href). Well formedness errors within the included XML document are always fatal.
Thanks.
[1] http://www.w3.org/TR/xinclude/#dt-resource-error
Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas <at> ca.ibm.com
E-mail: mrglavas <at> apache.org
"Peter A. Kirk" <pk <at> alpha-solutions.dk> wrote on 11/07/2010 07:50:09 PM:
> Hi
>
> I'm new to the Xerces xml parser, and would like some help loading/
> parsing xml documents using Xi Include.
>
> I have two xml files, "mainxml.xml" and "includexml.xml".
> MainXml looks like this:
> <?xml version="1.0" encoding="utf-8" ?>
> <config xmlns:xi="http://www.w3.org/2001/XInclude">
> <abc>
> <xi:include href="includexml.xml">
> <xi:fallback>
> <str name="fallback include">
> failure include
> </str>
> </xi:fallback>
> </xi:include>
> </abc>
> </config>
>
> and IncludeXml looks like:
> <str name="include">asd</str>
>
>
> I'm trying to load the MainXml file like this:
>
> DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
> dbf.setNamespaceAware(true);
> dbf.setXIncludeAware(true);
>
> DocumentBuilder db = dbf.newDocumentBuilder();
>
> Document doc = db.parse("mainxml.xml");
>
>
> Which works ok, unless there is an error in "includexml.xml". If
> there is an error, then the fallback is not used - why not? An error
> could be en empty "includexml.xml" file, or if the xml was invalid.
>
> How do I get the fallback to be used?
>
>
>
> Thanks,
> Peter
Hi Peter,
The fallback is only used in the event of a resource error [1]. For example, the file doesn't exist or possibly there's some kind of connection problem which prevents the parser from accessing the URI (specified as the value of href). Well formedness errors
within the included XML document are always fatal.
Thanks.
[1]
http://www.w3.org/TR/xinclude/#dt-resource-error
Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas <at> ca.ibm.com
E-mail: mrglavas <at> apache.org
"Peter A. Kirk" <pk <at> alpha-solutions.dk> wrote on 11/07/2010 07:50:09 PM:
> Hi
>
> I'm new to the Xerces xml parser, and would like some help loading/
> parsing xml documents using Xi Include.
>
> I have two xml files, "mainxml.xml" and "includexml.xml".
> MainXml looks like this:
> <?xml version="1.0" encoding="utf-8" ?>
> <config xmlns:xi="http://www.w3.org/2001/XInclude">
> <abc>
> <xi:include href="includexml.xml">
> <xi:fallback>
> <str name="fallback include">
> failure include
> </str>
> </xi:fallback>
> </xi:include>
> </abc>
> </config>
>
> and IncludeXml looks like:
> <str name="include">asd</str>
>
>
> I'm trying to load the MainXml file like this:
>
> DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
> dbf.setNamespaceAware(true);
> dbf.setXIncludeAware(true);
>
> DocumentBuilder db = dbf.newDocumentBuilder();
>
> Document doc = db.parse("mainxml.xml");
>
>
> Which works ok, unless there is an error in "includexml.xml". If
> there is an error, then the fallback is not used - why not? An error
> could be en empty "includexml.xml" file, or if the xml was invalid.
>
> How do I get the fallback to be used?
>
>
>
> Thanks,
> Peter
"Peter A. Kirk" <pk <at> alpha-solutions.dk> wrote on 11/07/2010 10:09:14 PM:
> OK, thanks. I've been trying to read the w3.org descriptions of
> include and fallback, and I was coming to the conclusion that it wasby design.
>
> Unfortunate for me though, because I'd like "all error fallback".
>
> I have for example some http requests for included xml, which the
> server cannot process sometimes (maybe the supplied url-parameters
> are incorrect, or a database error occurs at the server end) - and
> the server can have no way to know what "valid" xml to return. So I
> just tried to get it to return "empty" xml - but found this could
> not be parsed, and had hoped that the "fallback" would then handle it.
To get the fallback what you really need here is an IOException, not an empty file but some kind of failure to read from the URL. You could even register an EntityResolver and force an IOException to be thrown from it based on something you read from the HTTP response. This IOException will be caught by the XInclude processor, reported as a resource error and then the fallback you specified will be used.
> For example, my "GeneralConfig" web-app could be called like this:
>
> <xi:include href="http://localhost/GeneralConfig?cfg=abc_config" >
> </xi:include>
>
> And it should read the config from a database which matches the
> "cfg=abc_config" parameter, and return it to the caller.
>
> But, if there is no config matching this name in the database, or if
> the database is down for example, then I just returned nothing. But
> this causes the whole xml parsing to fail.
>
> /Peter
>
> From: Michael Glavassevich [mrglavas <at> ca.ibm.com]
> Sent: Monday, 8 November 2010 15:53
> To: j-users <at> xerces.apache.org
> Subject: Re: How to use xi include and fallback
>
> Hi Peter,
>
> The fallback is only used in the event of a resource error [1]. For
> example, the file doesn't exist or possibly there's some kind of
> connection problem which prevents the parser from accessing the URI
> (specified as the value of href). Well formedness errors within the
> included XML document are always fatal.
>
> Thanks.
>
> [1] http://www.w3.org/TR/xinclude/#dt-resource-error
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas <at> ca.ibm.com
> E-mail: mrglavas <at> apache.org
>
> "Peter A. Kirk" <pk <at> alpha-solutions.dk> wrote on 11/07/2010 07:50:09 PM:
>
> > Hi
> >
> > I'm new to the Xerces xml parser, and would like some help loading/
> > parsing xml documents using Xi Include.
> >
> > I have two xml files, "mainxml.xml" and "includexml.xml".
> > MainXml looks like this:
> > <?xml version="1.0" encoding="utf-8" ?>
> > <config xmlns:xi="http://www.w3.org/2001/XInclude">
> > <abc>
> > <xi:include href="includexml.xml">
> > <xi:fallback>
> > <str name="fallback include">
> > failure include
> > </str>
> > </xi:fallback>
> > </xi:include>
> > </abc>
> > </config>
> >
> > and IncludeXml looks like:
> > <str name="include">asd</str>
> >
> >
> > I'm trying to load the MainXml file like this:
> >
> > DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
> > dbf.setNamespaceAware(true);
> > dbf.setXIncludeAware(true);
> >
> > DocumentBuilder db = dbf.newDocumentBuilder();
> >
> > Document doc = db.parse("mainxml.xml");
> >
> >
> > Which works ok, unless there is an error in "includexml.xml". If
> > there is an error, then the fallback is not used - why not? An error
> > could be en empty "includexml.xml" file, or if the xml was invalid.
> >
> > How do I get the fallback to be used?
> >
> >
> >
> > Thanks,
> > Peter
Thanks.
Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas <at> ca.ibm.com
E-mail: mrglavas <at> apache.org
"Peter A. Kirk" <pk <at> alpha-solutions.dk> wrote on 11/07/2010 10:09:14 PM:
> OK, thanks. I've been trying to read the w3.org descriptions of
> include and fallback, and I was coming to the conclusion that it wasby design.
>
> Unfortunate for me though, because I'd like "all error fallback".
>
> I have for example some http requests for included xml, which the
> server cannot process sometimes (maybe the supplied url-parameters
> are incorrect, or a database error occurs at the server end) - and
> the server can have no way to know what "valid" xml to return. So I
> just tried to get it to return "empty" xml - but found this could
> not be parsed, and had hoped that the "fallback" would then handle it.
To get the fallback what you really need here is an IOException, not an empty file but some kind of failure to read from the URL. You could even register an EntityResolver and force an IOException to be thrown from it based on something you read from the
HTTP response. This IOException will be caught by the XInclude processor, reported as a resource error and then the fallback you specified will be used.
> For example, my "GeneralConfig" web-app could be called like this:
>
> <xi:include href="http://localhost/GeneralConfig?cfg=abc_config" >
> </xi:include>
>
> And it should read the config from a database which matches the
> "cfg=abc_config" parameter, and return it to the caller.
>
> But, if there is no config matching this name in the database, or if
> the database is down for example, then I just returned nothing. But
> this causes the whole xml parsing to fail.
>
> /Peter
>
> From: Michael Glavassevich [mrglavas <at> ca.ibm.com]
> Sent: Monday, 8 November 2010 15:53
> To: j-users <at> xerces.apache.org
> Subject: Re: How to use xi include and fallback
>
> Hi Peter,
>
> The fallback is only used in the event of a resource error [1]. For
> example, the file doesn't exist or possibly there's some kind of
> connection problem which prevents the parser from accessing the URI
> (specified as the value of href). Well formedness errors within the
> included XML document are always fatal.
>
> Thanks.
>
> [1]
http://www.w3.org/TR/xinclude/#dt-resource-error
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas <at> ca.ibm.com
> E-mail: mrglavas <at> apache.org
>
> "Peter A. Kirk" <pk <at> alpha-solutions.dk> wrote on 11/07/2010 07:50:09 PM:
>
> > Hi
> >
> > I'm new to the Xerces xml parser, and would like some help loading/
> > parsing xml documents using Xi Include.
> >
> > I have two xml files, "mainxml.xml" and "includexml.xml".
> > MainXml looks like this:
> > <?xml version="1.0" encoding="utf-8" ?>
> > <config xmlns:xi="http://www.w3.org/2001/XInclude">
> > <abc>
> > <xi:include href="includexml.xml">
> > <xi:fallback>
> > <str name="fallback include">
> > failure include
> > </str>
> > </xi:fallback>
> > </xi:include>
> > </abc>
> > </config>
> >
> > and IncludeXml looks like:
> > <str name="include">asd</str>
> >
> >
> > I'm trying to load the MainXml file like this:
> >
> > DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
> > dbf.setNamespaceAware(true);
> > dbf.setXIncludeAware(true);
> >
> > DocumentBuilder db = dbf.newDocumentBuilder();
> >
> > Document doc = db.parse("mainxml.xml");
> >
> >
> > Which works ok, unless there is an error in "includexml.xml". If
> > there is an error, then the fallback is not used - why not? An error
> > could be en empty "includexml.xml" file, or if the xml was invalid.
> >
> > How do I get the fallback to be used?
> >
> >
> >
> > Thanks,
> > Peter
Thanks.
Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas <at> ca.ibm.com
E-mail: mrglavas <at> apache.org
Hi, When I try to build Xerces-J with gcj as my jdk, it fails with compile: [copy] Copying 23 files to /var/tmp/paludis/build/dev-java-Xerces-J-2.10.0/work/xerces-2_10_0/build/classes [xjavac] Compiling 704 source files to /var/tmp/paludis/build/dev-java-Xerces-J-2.10.0/work/xerces-2_10_0/build/classes [xjavac] Compliance level '1.5' is incompatible with source level '1.6'. A compliance level '1.6' or better is required The problem is that Xerces-J is setting the source level with ant's built-in ant.java.version, which is set incorrectly for gcj. I filed a bug with ant at https://issues.apache.org/bugzilla/show_bug.cgi?id=50256 but they said that Xerces-J shouldn't be using ant.java.version to set the source level anyway, so is this a bug with Xerces-J? Thanks, Eric
Eric Smith <eric225125 <at> gmail.com> wrote on 11/11/2010 04:10:54 PM:
> Hi,
>
> When I try to build Xerces-J with gcj as my jdk, it fails with
>
> compile:
> [copy] Copying 23 files to
> /var/tmp/paludis/build/dev-java-Xerces-J-2.10.0/work/xerces-2_10_0/
> build/classes
> [xjavac] Compiling 704 source files to
> /var/tmp/paludis/build/dev-java-Xerces-J-2.10.0/work/xerces-2_10_0/
> build/classes
> [xjavac] Compliance level '1.5' is incompatible with source level '1.6'. A
> compliance level '1.6' or better is required
>
> The problem is that Xerces-J is setting the source level with ant's
> built-in ant.java.version, which is set incorrectly for gcj. I filed
> a bug with ant at
> https://issues.apache.org/bugzilla/show_bug.cgi?id=50256
> but they said that Xerces-J shouldn't be using ant.java.version to
> set the source level anyway, so is this a bug with Xerces-J?
No. This was intentional so that class files are generated at the same level as the JDK used to compile Xerces. The source level cannot be lower than the target.
> Thanks,
> Eric
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe <at> xerces.apache.org
> For additional commands, e-mail: j-users-help <at> xerces.apache.org
Thanks.
Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas <at> ca.ibm.com
E-mail: mrglavas <at> apache.org
Why wouldn't source and target be hardcoded in the build? Xerces source compliance is not a dynamic thing. It should be hardcoded in the build to whatever is level Xerces advertises it to be. According to the Java docs [1] the default behavior is (assuming you hardcode -source).... "If -source is 1.3, the value of -target is 1.4" "For all other values of -source, the value of -target is the value of -source." I would suggest just setting both -source and -target to whatever you deem the minimum supported platform. For JDK1.3... -source 1.3 -target 1.4 for JDK1.4... -source 1.4 -target 1.4 With this, it doesn't matter which version of the JDK you compile under. The generated binary will always work (barring API incompatibilities which do exist in, at least, StringBuffer between JDK1.3 and JDK1.4) with the minimum JDK as defined by the hardcoded -source and -target values. [1] http://download.oracle.com/javase/6/docs/technotes/tools/windows/javac.html Jake On Thu, 11 Nov 2010 16:48:29 -0500 Michael Glavassevich <mrglavas <at> ca.ibm.com> wrote: > Eric Smith <eric225125 <at> gmail.com> wrote on 11/11/2010 04:10:54 PM: > >> Hi, >> >> When I try to build Xerces-J with gcj as my jdk, it fails with >> >> compile: >> [copy] Copying 23 files to >> /var/tmp/paludis/build/dev-java-Xerces-J-2.10.0/work/xerces-2_10_0/ >> build/classes >> [xjavac] Compiling 704 source files to >> /var/tmp/paludis/build/dev-java-Xerces-J-2.10.0/work/xerces-2_10_0/ >> build/classes >> [xjavac] Compliance level '1.5' is incompatible with source level '1.6'. > A >> compliance level '1.6' or better is required >> >> The problem is that Xerces-J is setting the source level with ant's >> built-in ant.java.version, which is set incorrectly for gcj. I filed >> a bug with ant at >> https://issues.apache.org/bugzilla/show_bug.cgi?id=50256 >> but they said that Xerces-J shouldn't be using ant.java.version to >> set the source level anyway, so is this a bug with Xerces-J? > > No. This was intentional so that class files are generated at the same > level as the JDK used to compile Xerces. The source level cannot be lower > than the target. > >> Thanks, >> Eric >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: j-users-unsubscribe <at> xerces.apache.org >> For additional commands, e-mail: j-users-help <at> xerces.apache.org > > Thanks. > > Michael Glavassevich > XML Parser Development > IBM Toronto Lab > E-mail: mrglavas <at> ca.ibm.com > E-mail: mrglavas <at> apache.org
"Jacob Kjome" <hoju <at> visi.com> wrote on 11/12/2010 01:29:38 PM:
> Why wouldn't source and target be hardcoded in the build? Xerces source
> compliance is not a dynamic thing. It should be hardcoded in the build to
> whatever is level Xerces advertises it to be.
Except that there's isn't just one level. There will be 1.3 and 1.4 (for the XML Schema 1.1 support which already has 1.4 dependencies; we may start adding asserts) binaries built for the next release. This allows us to maintain a single build.xml for both.
> According to the Javadocs [1] the default behavior is (assuming you
> hardcode -source)....
>
> "If -source is 1.3, the value of -target is 1.4"
> "For all other values of -source, the value of -target is
> the value of
> -source."
>
> I would suggest just setting both -source and -target to whatever
> you deem the
> minimum supported platform.
>
> For JDK1.3...
> -source 1.3
> -target 1.4
>
> for JDK1.4...
> -source 1.4
>
> -target 1.4
>
> With this, it doesn't matter which version of the JDK you compile under. The
> generated binary will always work (barring API incompatibilities which do
> exist in, at least, StringBuffer between JDK1.3 and JDK1.4) with the minimum
> JDK as defined by the hardcoded -source and -target values.
It does matter what JDK you compile under for the reason you just stated.
> [1]
> http://download.oracle.com/javase/6/docs/technotes/tools/windows/javac.html
>
>
> Jake
>
> On Thu, 11 Nov 2010 16:48:29 -0500
> Michael Glavassevich <mrglavas <at> ca.ibm.com> wrote:
> > Eric Smith <eric225125 <at> gmail.com> wrote on 11/11/2010 04:10:54 PM:
> >
> >> Hi,
> >>
> >> When I try to build Xerces-J with gcj as my jdk, it fails with
> >>
> >> compile:
> >> [copy] Copying 23 files to
> >> /var/tmp/paludis/build/dev-java-Xerces-J-2.10.0/work/xerces-2_10_0/
> >> build/classes
> >> [xjavac] Compiling 704 source files to
> >> /var/tmp/paludis/build/dev-java-Xerces-J-2.10.0/work/xerces-2_10_0/
> >> build/classes
> >> [xjavac] Compliance level '1.5' is incompatible with source level '1.6'.
> > A
> >> compliance level '1.6' or better is required
> >>
> >> The problem is that Xerces-J is setting the source level with ant's
> >> built-in ant.java.version, which is set incorrectly for gcj. I filed
> >> a bug with ant at
> >> https://issues.apache.org/bugzilla/show_bug.cgi?id=50256
> >> but they said that Xerces-J shouldn't be using ant.java.version to
> >> set the source level anyway, so is this a bug with Xerces-J?
> >
> > No. This was intentional so that class files are generated at the same
> > level as the JDK used to compile Xerces. The source level cannot be lower
> > than the target.
> >
> >> Thanks,
> >> Eric
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: j-users-unsubscribe <at> xerces.apache.org
> >> For additional commands, e-mail: j-users-help <at> xerces.apache.org
> >
> > Thanks.
> >
> > Michael Glavassevich
> > XML Parser Development
> > IBM Toronto Lab
> > E-mail: mrglavas <at> ca.ibm.com
> > E-mail: mrglavas <at> apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe <at> xerces.apache.org
> For additional commands, e-mail: j-users-help <at> xerces.apache.org
Thanks.
Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas <at> ca.ibm.com
E-mail: mrglavas <at> apache.org
I’m pretty new to xsd and am running into some issues when trying to use Xinclude in my schema (with Xerces).
1) All the sample documentation seemed to imply that you could import xinclude as follows:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xi="http://www.w3.org/2001/XInclude" >
<xs:import namespace="http://www.w3.org/2001/XInclude"
schemaLocation=”xinclude.xsd"/>
However I could only get this to work with a full URL:
i.e. schemaLocation=”http://www.w3.org/2001/xinclude.xsd”
Does everyone else have xinclude.xsd downloaded somewhere local?
2) When I actually go to include references to an inclusion in my xml file I’m hitting the following error:
cvc-complex-type.2.4.a: Invalid content was found starting with element 'xi:include'. One of '{"http://www.w3.org/2001/XInclude":include, GlobalConfiguration, TestTemplate, TestGroup}' is expected.
Xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xi="http://www.w3.org/2001/XInclude" >
<xs:import namespace="http://www.w3.org/2001/XInclude"
schemaLocation="http://www.w3.org/2001/xinclude.xsd"/>
<xs:element name="Gauntlet">
<xs:complexType>
<xs:sequence>
<xs:choice maxOccurs="unbounded">
<xs:element ref="xi:include" minOccurs="0" />
<xs:element ref="GlobalConfiguration" maxOccurs="1" />
<xs:element ref="TestTemplate" minOccurs="0" maxOccurs="unbounded" />
<xs:element ref="TestGroup" maxOccurs="unbounded" />
</xs:choice>
</xs:sequence>
</xs:complexType>
XML:
<?xml version="1.0" encoding="UTF-8"?>
<Gauntlet xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="fragment.xml" />
Thanks for any help,
Ben
RSS Feed7 | |
|---|---|
8 | |
25 | |
5 | |
6 | |
11 | |
14 | |
11 | |
24 | |
10 | |
10 | |
3 | |
13 | |
32 | |
18 | |
52 | |
12 | |
11 | |
6 | |
2 | |
17 | |
2 | |
14 | |
33 | |
39 | |
11 | |
10 | |
20 | |
4 | |
19 | |
9 | |
18 | |
27 | |
16 | |
54 | |
21 | |
32 | |
23 | |
20 | |
11 | |
55 | |
40 | |
36 | |
69 | |
72 | |
45 | |
48 | |
33 | |
58 | |
16 | |
56 | |
21 | |
41 | |
32 | |
67 | |
88 | |
21 | |
30 | |
24 | |
31 | |
27 | |
53 | |
45 | |
70 | |
36 | |
65 | |
34 | |
66 | |
59 | |
15 | |
60 | |
50 | |
33 | |
53 | |
45 | |
43 | |
72 | |
119 | |
94 | |
68 | |
96 | |
166 | |
72 | |
43 | |
79 | |
47 | |
53 | |
75 | |
24 | |
26 | |
22 | |
61 | |
65 | |
34 | |
78 | |
68 | |
72 | |
26 | |
28 | |
112 | |
78 | |
103 | |
104 | |
97 | |
80 | |
94 | |
103 | |
91 | |
121 | |
80 | |
123 | |
126 | |
96 | |
158 | |
106 | |
132 | |
113 | |
146 | |
12 |