Re: [Sax-devel] Resolve all entities
Brought to you by:
dmegginson
|
From: Vallone, P. Mr C. U. A. <Phi...@us...> - 2008-04-28 15:15:29
|
Hi Thank you for your help.
The problem was is the if statement. When I get rid of it.. Everything
works.
Thanks for the help!
Phil
-----Original Message-----
From: sax...@li...
[mailto:sax...@li...] On Behalf Of David
Megginson
Sent: Monday, April 28, 2008 10:01 AM
To: List for developers contributing to SAX itself.
Subject: Re: [Sax-devel] Resolve all entities
2008/4/24 Vallone, Philip Mr CTR USA AMC <Phi...@us...>:
> I was wondering if you could provide some guidance on resolving
> entities before they are processed. I have the following java code
> that will list an entities systemIDs referenced in an XML document.
> This works well except if I have an entity referenced that references
> a list of entities (like a catalog of entities) or an entity that is
not used.
It looks to me like a bug int he parser you're using. Your entity
resolver should be invoked for all references, including the parameter
entity reference %commonEntities;. Have you tried adding a print
statement outside the if block, to see if for some reason it's not
coming in with a file: scheme?
>
> The following XML returns:
>
> System ID: file:/C:/path/driverlicense.dtd System ID:
> file:/C:/path/phone.ent
>
> Since "commonEnties" was not used, nothing is returned. How do I
> return all entites files referenced?
>
>
> ********code***********
> Sample XML test.xml
>
> <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE DRIVERSLICENSE
> SYSTEM "driverlicense.dtd" [
> <!ENTITY phone SYSTEM "phone.ent">
> <!ENTITY % commonEnties SYSTEM 'c:/temp/common.ent'>
> %commonEnties;
> ]>
> <?xml-stylesheet type="text/xsl" href="driverslicense.xslt"?>
> <DRIVERSLICENSE>
> <NAME nickname="Joey">JOE</NAME>
> <STREET>1313 Mocking Bird</STREET>
> <CITY>Here</CITY>
> <STATE>NY</STATE>
> <ZIP>11738</ZIP>
> <CELL>123-456-7890</CELL>
> ☎
> </DRIVERSLICENSE>
>
>
> Java code:
>
> private void resolver(java.awt.event.ActionEvent evt) {
>
> try {
> // Create an XML parser
> DocumentBuilder builder =
> DocumentBuilderFactory.newInstance().newDocumentBuilder();
> // Install the entity resolver
> builder.setEntityResolver(new MyResolver());
> // Parse the XML file
> org.w3c.dom.Document doc = builder.parse(new
> File("C:/path/test.xml"));
>
> } catch (SAXException e) {
> // A parsing error occurred; the xml input is not valid
> } catch (ParserConfigurationException e) {
> } catch (IOException e) {
> }
>
> }
>
> public class MyResolver implements EntityResolver {
> // This method is called whenever an external entity is
accessed
> // for the first time.
> public InputSource resolveEntity(String publicId, String
> systemId) {
> try {
> // Wrap the systemId in a URI object to make it
> convenient
> // to extract the components of the systemId
> URI uri = new URI(systemId);
>
> System.out.println("System ID: " + systemId);
>
>
> // Check if external source is a file
> if ("file".equals(uri.getScheme())) {
> String filename = uri.getSchemeSpecificPart();
>
> return new InputSource(new FileReader(filename));
> } else {
>
> }
> } catch (URISyntaxException e) {
> System.err.println(e.toString());
> } catch (IOException e) {
> }
>
> // Returning null causes the caller to try accessing the
> systemid
> return null;
> }
> }
All the best,
David
------------------------------------------------------------------------
-
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference Don't
miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/j
avaone
_______________________________________________
List: sax-devel, sax...@li...
See: http://www.saxproject.org/
https://lists.sourceforge.net/lists/listinfo/sax-devel
|