Entity and classpath

Discussion in 'XML' started by cochrane68@hotmail.com, Nov 8, 2005.

  1. Guest

    I'm trying to access an XML snippet based on the classpath. I know how
    to use a snippet based on the absolute path of a file using:

    <!DOCTYPE project [
    <!ENTITY test SYSTEM "file:C:\Documents and
    Settings\chris\Desktop\test2.xml">
    ]>

    However, this is going to be used as part of a J2EE application, and I
    need a way to access an XML snippet based on the classpath. So my
    DOCTYPE declaration would look something like:

    <!DOCTYPE project [
    <!ENTITY test SYSTEM "resource:test2.xml">
    ]>

    Is there anyway to do this directly in the XML, or does XML have no
    concept of a classpath?
     
    , Nov 8, 2005
    #1
    1. Advertising

  2. wrote:
    > I'm trying to access an XML snippet based on the classpath. I know how
    > to use a snippet based on the absolute path of a file using:
    >
    > <!DOCTYPE project [
    > <!ENTITY test SYSTEM "file:C:\Documents and
    > Settings\chris\Desktop\test2.xml">
    > ]>
    >
    > However, this is going to be used as part of a J2EE application, and I
    > need a way to access an XML snippet based on the classpath. So my
    > DOCTYPE declaration would look something like:
    >
    > <!DOCTYPE project [
    > <!ENTITY test SYSTEM "resource:test2.xml">
    > ]>
    >
    > Is there anyway to do this directly in the XML, or does XML have no
    > concept of a classpath?
    >


    XML has no concept of classpath, but it has a concept of entity resolver

    with java, you just have to provide an implementation of the interface
    org.xml.sax.EntityResolver that has a single method ; if it returns
    null, the parsers will try to resolve the external identifier by its
    own, otherwise (the case where the system identifier starts with
    "resource:") you have to supply yourself the resource

    to plug this entity resolver to the XML parser, refer to
    javax.xml.parsers.DocumentBuilder or to org.xml.sax.XMLReader

    --
    Cordialement,

    ///
    (. .)
    -----ooO--(_)--Ooo-----
    | Philippe Poulard |
    -----------------------
     
    Philippe Poulard, Nov 8, 2005
    #2
    1. Advertising

  3. wrote:

    > However, this is going to be used as part of a J2EE application, and I
    > need a way to access an XML snippet based on the classpath. So my
    > DOCTYPE declaration would look something like:
    >
    > <!DOCTYPE project [
    > <!ENTITY test SYSTEM "resource:test2.xml">
    > ]>
    >
    > Is there anyway to do this directly in the XML, or does XML have no
    > concept of a classpath?


    A Java class path? No, XML is not Java specific.
    If you are using Java tools/APIs then you need to build your own
    implementation of the interface org.xml.sax.EntityResolver I think.
    But chances are someone in a group or forum about J2EE knows more about
    that and might even be able to point you to existing implementations if
    that resource: URL is common use there.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Nov 8, 2005
    #3
  4. Guest

    That's what I thought, but hoping there was an easier way. Thanks for
    the responses!
     
    , Nov 8, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Flip
    Replies:
    3
    Views:
    7,377
    Tony Morris
    Feb 9, 2004
  2. Gabe
    Replies:
    3
    Views:
    1,107
  3. Replies:
    2
    Views:
    782
  4. Replies:
    2
    Views:
    1,141
    Mike Schilling
    Mar 2, 2008
  5. markla
    Replies:
    1
    Views:
    571
    Steven Cheng
    Oct 6, 2008
Loading...

Share This Page