[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">&nbsp;</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>&quot;Peter A. Kirk&quot; &lt;pk@alpha-solutions.dk&gt; wrote on 11/07/2010 \
10:09:14 PM:<br> <br>
&gt; OK, thanks. I've been trying to read the w3.org descriptions of <br>
&gt; include and fallback, and I was coming to the conclusion that it wasby \
design.</tt><br> <tt>&gt; &nbsp;</tt><br>
<tt>&gt; Unfortunate for me though, because I'd like &quot;all error \
fallback&quot;.</tt><br> <tt>&gt; &nbsp;</tt><br>
<tt>&gt; I have for example some http requests for included xml, which the <br>
&gt; server cannot process sometimes (maybe the supplied url-parameters <br>
&gt; are incorrect, or a database error occurs at the server end) - and <br>
&gt; the server can have no way to know what &quot;valid&quot; xml to return. So I \
<br> &gt; just tried to get it to return &quot;empty&quot; xml - but found this could \
<br> &gt; not be parsed, and had hoped that the &quot;fallback&quot; 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>&gt; For example, my &quot;GeneralConfig&quot; web-app could be called like \
this:</tt><br> <tt>&gt; &nbsp;</tt><br>
<tt>&gt; &lt;xi:include \
href=&quot;http://localhost/GeneralConfig?cfg=abc_config&quot; &gt;<br> &gt; \
&lt;/xi:include&gt; &nbsp; &nbsp; &nbsp;</tt><br> <tt>&gt; &nbsp;</tt><br>
<tt>&gt; And it should read the config from a database which matches the <br>
&gt; &quot;cfg=abc_config&quot; parameter, and return it to the caller.</tt><br>
<tt>&gt; &nbsp;</tt><br>
<tt>&gt; But, if there is no config matching this name in the database, or if<br>
&gt; the database is down for example, then I just returned nothing. But <br>
&gt; this causes the whole xml parsing to fail.</tt><br>
<tt>&gt; &nbsp;</tt><br>
<tt>&gt; /Peter</tt><br>
<tt>&gt; &nbsp;</tt><br>
<tt>&gt; From: Michael Glavassevich [mrglavas@ca.ibm.com]<br>
&gt; Sent: Monday, 8 November 2010 15:53<br>
&gt; To: j-users@xerces.apache.org<br>
&gt; Subject: Re: How to use xi include and fallback<br>
&gt;</tt><br>
<tt>&gt; Hi Peter,<br>
&gt; <br>
&gt; The fallback is only used in the event of a resource error [1]. For <br>
&gt; example, the file doesn't exist or possibly there's some kind of <br>
&gt; connection problem which prevents the parser from accessing the URI <br>
&gt; (specified as the value of href). Well formedness errors within the <br>
&gt; included XML document are always fatal.<br>
&gt; <br>
&gt; Thanks.<br>
&gt; <br>
&gt; [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>
&gt; <br>
&gt; Michael Glavassevich<br>
&gt; XML Parser Development<br>
&gt; IBM Toronto Lab<br>
&gt; E-mail: mrglavas@ca.ibm.com<br>
&gt; E-mail: mrglavas@apache.org<br>
&gt; <br>
&gt; &quot;Peter A. Kirk&quot; &lt;pk@alpha-solutions.dk&gt; wrote on 11/07/2010 \
07:50:09 PM:<br> &gt; <br>
&gt; &gt; Hi<br>
&gt; &gt; &nbsp;<br>
&gt; &gt; I'm new to the Xerces xml parser, and would like some help loading/<br>
&gt; &gt; parsing xml documents using Xi Include.<br>
&gt; &gt; &nbsp;<br>
&gt; &gt; I have two xml files, &quot;mainxml.xml&quot; and \
&quot;includexml.xml&quot;.<br> &gt; &gt; MainXml looks like this:<br>
&gt; &gt; &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;<br>
&gt; &gt; &lt;config xmlns:xi=&quot;http://www.w3.org/2001/XInclude&quot;&gt;<br>
&gt; &gt; &nbsp;&lt;abc&gt;<br>
&gt; &gt; &nbsp; &lt;xi:include href=&quot;includexml.xml&quot;&gt;<br>
&gt; &gt; &nbsp; &nbsp;&lt;xi:fallback&gt;<br>
&gt; &gt; &nbsp; &nbsp; &lt;str name=&quot;fallback include&quot;&gt;<br>
&gt; &gt; &nbsp; &nbsp; &nbsp; failure include<br>
&gt; &gt; &nbsp; &nbsp; &lt;/str&gt;<br>
&gt; &gt; &nbsp; &nbsp;&lt;/xi:fallback&gt;<br>
&gt; &gt; &nbsp; &lt;/xi:include&gt;<br>
&gt; &gt; &nbsp;&lt;/abc&gt;<br>
&gt; &gt; &lt;/config&gt;<br>
&gt; &gt; &nbsp;<br>
&gt; &gt; and IncludeXml looks like:<br>
&gt; &gt; &lt;str name=&quot;include&quot;&gt;asd&lt;/str&gt;<br>
&gt; &gt; &nbsp;<br>
&gt; &gt; &nbsp;<br>
&gt; &gt; I'm trying to load the MainXml file like this:<br>
&gt; &gt; &nbsp;<br>
&gt; &gt; DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();<br>
&gt; &gt; dbf.setNamespaceAware(true);<br>
&gt; &gt; dbf.setXIncludeAware(true);<br>
&gt; &gt; &nbsp; &nbsp;<br>
&gt; &gt; DocumentBuilder db = dbf.newDocumentBuilder();<br>
&gt; &gt; &nbsp; &nbsp;<br>
&gt; &gt; Document doc = db.parse(&quot;mainxml.xml&quot;);<br>
&gt; &gt; &nbsp;<br>
&gt; &gt; &nbsp;<br>
&gt; &gt; Which works ok, unless there is an error in &quot;includexml.xml&quot;. If \
<br> &gt; &gt; there is an error, then the fallback is not used - why not? An \
error<br> &gt; &gt; could be en empty &quot;includexml.xml&quot; file, or if the xml \
was invalid.<br> &gt; &gt; &nbsp;<br>
&gt; &gt; How do I get the fallback to be used?<br>
&gt; &gt; &nbsp;<br>
&gt; &gt; &nbsp;<br>
&gt; &gt; &nbsp;<br>
&gt; &gt; Thanks,<br>
&gt; &gt; 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