[prev in list] [next in list] [prev in thread] [next in thread]
List: xerces-j-dev
Subject: RE: How to use xi include and fallback
From: "Peter A. Kirk" <pk () alpha-solutions ! dk>
Date: 2010-11-08 3:30:46
Message-ID: 09B0F2676706A94B83A48D01A15AA0D3017FA628DB44 () alphaextmail ! as1 ! alphasolutions ! dk
[Download RAW message or body]
Yes thanks - I thought about something like that as soon as I posted...
________________________________
From: Michael Glavassevich [mrglavas@ca.ibm.com]
Sent: Monday, 8 November 2010 16:27
To: j-users@xerces.apache.org
Subject: RE: How to use xi include and fallback
"Peter A. Kirk" <pk@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@ca.ibm.com]
> Sent: Monday, 8 November 2010 15:53
> To: j-users@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@ca.ibm.com
> E-mail: mrglavas@apache.org
>
> "Peter A. Kirk" <pk@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@ca.ibm.com
E-mail: mrglavas@apache.org
[Attachment #3 (text/html)]
<html dir="ltr"><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="MSHTML 8.00.6001.18975">
<style title="owaParaStyle"><!--P {
MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px
}
--></style>
</head>
<body ocsi="x">
<div dir="ltr"><font color="#000000" size="2" face="Tahoma">Yes thanks - I thought \
about something like that as soon as I posted...</font></div> <div \
dir="ltr"> </div> <div style="DIRECTION: ltr" id="divRpF219147">
<hr tabindex="-1">
<font size="2" face="Tahoma"><b>From:</b> Michael Glavassevich \
[mrglavas@ca.ibm.com]<br> <b>Sent:</b> Monday, 8 November 2010 16:27<br>
<b>To:</b> j-users@xerces.apache.org<br>
<b>Subject:</b> RE: How to use xi include and fallback<br>
</font><br>
</div>
<div></div>
<div>
<p><tt>"Peter A. Kirk" <pk@alpha-solutions.dk> wrote on 11/07/2010 \
10:09:14 PM:<br> <br>
> OK, thanks. I've been trying to read the w3.org descriptions of <br>
> include and fallback, and I was coming to the conclusion that it wasby \
design.</tt><br> <tt>> </tt><br>
<tt>> Unfortunate for me though, because I'd like "all error \
fallback".</tt><br> <tt>> </tt><br>
<tt>> I have for example some http requests for included xml, which the <br>
> server cannot process sometimes (maybe the supplied url-parameters <br>
> are incorrect, or a database error occurs at the server end) - and <br>
> the server can have no way to know what "valid" xml to return. So I \
<br> > just tried to get it to return "empty" xml - but found this could \
<br> > not be parsed, and had hoped that the "fallback" would then \
handle it.</tt><br> <br>
<tt>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.</tt><br> <br>
<tt>> For example, my "GeneralConfig" web-app could be called like \
this:</tt><br> <tt>> </tt><br>
<tt>> <xi:include \
href="http://localhost/GeneralConfig?cfg=abc_config" ><br> > \
</xi:include> </tt><br> <tt>> </tt><br>
<tt>> And it should read the config from a database which matches the <br>
> "cfg=abc_config" parameter, and return it to the caller.</tt><br>
<tt>> </tt><br>
<tt>> But, if there is no config matching this name in the database, or if<br>
> the database is down for example, then I just returned nothing. But <br>
> this causes the whole xml parsing to fail.</tt><br>
<tt>> </tt><br>
<tt>> /Peter</tt><br>
<tt>> </tt><br>
<tt>> From: Michael Glavassevich [mrglavas@ca.ibm.com]<br>
> Sent: Monday, 8 November 2010 15:53<br>
> To: j-users@xerces.apache.org<br>
> Subject: Re: How to use xi include and fallback<br>
></tt><br>
<tt>> Hi Peter,<br>
> <br>
> The fallback is only used in the event of a resource error [1]. For <br>
> example, the file doesn't exist or possibly there's some kind of <br>
> connection problem which prevents the parser from accessing the URI <br>
> (specified as the value of href). Well formedness errors within the <br>
> included XML document are always fatal.<br>
> <br>
> Thanks.<br>
> <br>
> [1] <a href="http://www.w3.org/TR/xinclude/#dt-resource-error" target="_blank">
http://www.w3.org/TR/xinclude/#dt-resource-error</a><br>
> <br>
> Michael Glavassevich<br>
> XML Parser Development<br>
> IBM Toronto Lab<br>
> E-mail: mrglavas@ca.ibm.com<br>
> E-mail: mrglavas@apache.org<br>
> <br>
> "Peter A. Kirk" <pk@alpha-solutions.dk> wrote on 11/07/2010 \
07:50:09 PM:<br> > <br>
> > Hi<br>
> > <br>
> > I'm new to the Xerces xml parser, and would like some help loading/<br>
> > parsing xml documents using Xi Include.<br>
> > <br>
> > I have two xml files, "mainxml.xml" and \
"includexml.xml".<br> > > MainXml looks like this:<br>
> > <?xml version="1.0" encoding="utf-8" ?><br>
> > <config xmlns:xi="http://www.w3.org/2001/XInclude"><br>
> > <abc><br>
> > <xi:include href="includexml.xml"><br>
> > <xi:fallback><br>
> > <str name="fallback include"><br>
> > failure include<br>
> > </str><br>
> > </xi:fallback><br>
> > </xi:include><br>
> > </abc><br>
> > </config><br>
> > <br>
> > and IncludeXml looks like:<br>
> > <str name="include">asd</str><br>
> > <br>
> > <br>
> > I'm trying to load the MainXml file like this:<br>
> > <br>
> > DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();<br>
> > dbf.setNamespaceAware(true);<br>
> > dbf.setXIncludeAware(true);<br>
> > <br>
> > DocumentBuilder db = dbf.newDocumentBuilder();<br>
> > <br>
> > Document doc = db.parse("mainxml.xml");<br>
> > <br>
> > <br>
> > Which works ok, unless there is an error in "includexml.xml". If \
<br> > > there is an error, then the fallback is not used - why not? An \
error<br> > > could be en empty "includexml.xml" file, or if the xml \
was invalid.<br> > > <br>
> > How do I get the fallback to be used?<br>
> > <br>
> > <br>
> > <br>
> > Thanks,<br>
> > Peter</tt><br>
<br>
<tt>Thanks.</tt><br>
<br>
<tt>Michael Glavassevich<br>
XML Parser Development<br>
IBM Toronto Lab<br>
E-mail: mrglavas@ca.ibm.com</tt><br>
<tt>E-mail: mrglavas@apache.org</tt></p>
</div>
</body>
</html>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic