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

Phil Jarvis

Usenet Archive
Joined
Apr 2, 2004
Messages
6
Reaction score
0
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
 

Richard Tobin

Usenet Archive
Joined
Jan 6, 2000
Messages
4,251
Reaction score
0
Phil Jarvis said:
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
 

Phil Jarvis

Usenet Archive
Joined
Apr 2, 2004
Messages
6
Reaction score
0
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

Usenet Archive
Joined
Jan 6, 2000
Messages
4,251
Reaction score
0
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
 

Phil Jarvis

Usenet Archive
Joined
Apr 2, 2004
Messages
6
Reaction score
0
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
548,208
Messages
3,104,798
Members
249,594
Latest member
henrywalsh

Latest Threads

Top