Xml schema: how to achieve <!ENTITY x "y">

Discussion in 'XML' started by Phil Jarvis, Apr 2, 2004.

  1. Phil Jarvis

    Phil Jarvis Guest

    I have an XML Schema with regular expressions.

    e.g. <xsd:pattern value="[a-zA-Z]{1}[a-zA-Z0-9._=+-]*"/>

    I have other patterns in the same schema document which share regular
    expression substructure, like the string "[a-zA-Z0-9._=+-]"

    I'd like to do something like:

    <!ENTITY substring_pattern "[a-zA-Z0-9._=+-]">

    And revise my xml schema to look like:

    <xsd:pattern value="[a-zA-Z]{1}&substring_pattern;*"/>


    I can't figure out how to generate a reusable literal that can be
    embedded in attribute values within an XML schema document.

    <!ENTITY> isn't valid xml in an XML schema, at least not as far as my
    tests have shown in attempting to validate with a schema using such
    declarations.


    HELP!


    Signed,
    cut-and-pasting-for-now-but-tired-of-it


    --
    ----------

    Email from unknown persons will be blocked by spam filters.
    Please post replies to the news conference. Thank you.
     
    Phil Jarvis, Apr 2, 2004
    #1
    1. Advertising

  2. In article <pjlbc.163534$Cb.1653348@attbi_s51>,
    Phil Jarvis <> wrote:

    >I can't figure out how to generate a reusable literal that can be
    >embedded in attribute values within an XML schema document.


    Schemas don't provide an entity-like mechanism: they just do the
    validation bit of DTDs. if you want an entity, put a DTD on your
    schema and define one in the usual way.

    -- Richard
     
    Richard Tobin, Apr 2, 2004
    #2
    1. Advertising

  3. Phil Jarvis

    Phil Jarvis Guest

    I suspect that if I do what you suggest, presumably something like

    <!DOCTYPE MySchema SYSTEM "MySchema.dtd">

    for an XML schema document which otherwise looks like this:

    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    ...

    That both attempts to
    (a) run it as input for schema validated xml content or
    (b) run it as input for xml validation against the dted

    would be a disaster. (I'd have to define the whole
    XML Schema in the dtd, for starters, and XML Schema validators would
    probably STILL choke on the <!DOCTYPE > statement).

    DTD's and XML schema don't mix, I suspect, with the schema validation
    tools I use. So I must be missing what you had in mind. Could you give
    me an example?

    (FYI: I'm just using Sun J2SE 1.4.2 tools)

    Richard Tobin wrote:
    > In article <pjlbc.163534$Cb.1653348@attbi_s51>,
    > Phil Jarvis <> wrote:
    >
    >
    >>I can't figure out how to generate a reusable literal that can be
    >>embedded in attribute values within an XML schema document.

    >
    >
    > Schemas don't provide an entity-like mechanism: they just do the
    > validation bit of DTDs. if you want an entity, put a DTD on your
    > schema and define one in the usual way.
    >
    > -- Richard


    --
    ----------

    Email from unknown persons will be blocked by spam filters.
    Please post replies to the new conference. Thank you.
     
    Phil Jarvis, Apr 3, 2004
    #3
  4. Toni Uusitalo, Apr 3, 2004
    #4
  5. In article <teFbc.67340$JO3.39105@attbi_s04>,
    Phil Jarvis <> wrote:
    >I suspect that if I do what you suggest, presumably something like
    >
    ><!DOCTYPE MySchema SYSTEM "MySchema.dtd">
    >
    >for an XML schema document which otherwise looks like this:
    >
    ><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    > ...
    >
    >That both attempts to
    >(a) run it as input for schema validated xml content or
    >(b) run it as input for xml validation against the dted
    >
    >would be a disaster. (I'd have to define the whole
    >XML Schema in the dtd, for starters, and XML Schema validators would
    >probably STILL choke on the <!DOCTYPE > statement).


    There's a DTD for schemas at http://www.w3.org/2001/XMLSchema.dtd, but
    you don't need to use a complete DTD, just an internal subset with the
    entity you want. Of course if you validate it against an incomplete
    DTD it will be invalid, but you don't have to DTD-validate just to use
    an entity declaration.

    XML Schemas are XML documents, so no Schema validator should "choke"
    on a DOCTYPE statement. All XML processors are required to process
    the internal subset, so if you put your entity declaration there it
    should work.

    -- Richard
     
    Richard Tobin, Apr 4, 2004
    #5
  6. Phil Jarvis

    Phil Jarvis Guest

    Lots of good advice in these replies. I'll try it out.

    Thanks!

    Richard Tobin wrote:
    > In article <teFbc.67340$JO3.39105@attbi_s04>,
    > Phil Jarvis <> wrote:
    >
    >>I suspect that if I do what you suggest, presumably something like
    >>
    >><!DOCTYPE MySchema SYSTEM "MySchema.dtd">
    >>
    >>for an XML schema document which otherwise looks like this:
    >>
    >><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    >> ...
    >>
    >>That both attempts to
    >>(a) run it as input for schema validated xml content or
    >>(b) run it as input for xml validation against the dted
    >>
    >>would be a disaster. (I'd have to define the whole
    >>XML Schema in the dtd, for starters, and XML Schema validators would
    >>probably STILL choke on the <!DOCTYPE > statement).

    >
    >
    > There's a DTD for schemas at http://www.w3.org/2001/XMLSchema.dtd, but
    > you don't need to use a complete DTD, just an internal subset with the
    > entity you want. Of course if you validate it against an incomplete
    > DTD it will be invalid, but you don't have to DTD-validate just to use
    > an entity declaration.
    >
    > XML Schemas are XML documents, so no Schema validator should "choke"
    > on a DOCTYPE statement. All XML processors are required to process
    > the internal subset, so if you put your entity declaration there it
    > should work.
    >
    > -- Richard


    --
    ----------

    Email from unknown persons will be blocked by spam filters.
    Please post replies to the new conference. Thank you.
     
    Phil Jarvis, Apr 4, 2004
    #6
  7. Phil Jarvis

    Phil Jarvis Guest

    Just a followup, the answers (provided in replies) to my questions
    worked just fine against schema validation tools and such when I tried them.

    Thanks for your help.

    --
    ----------

    Email from unknown persons will be blocked by spam filters.
    Please post replies to the new conference. Thank you.
     
    Phil Jarvis, Apr 4, 2004
    #7
    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.

Share This Page