No way to use entities in a document using schema?

K

Kent Tong

Hi,

This is wha I'm trying to do:

<?xml version="1.0"?>
<!DOCTYPE library [
<!ENTITY foo "Some sentence...">
]>
<library xmlns="http://foo.com">
&foo;
</library>

But Xerces is saying that "library" element type is undefined. I can
understand that as library is defined in the "http://foo.com"
namespace. Does it means that it is impossible to use entities in
a document using schema/namespace?

If it is true, then it is impossible to split a large xml file into
several small files and then include them as external entites?

Thanks for any advice!
 
D

Dimitre Novatchev

Hi,

This is wha I'm trying to do:

<?xml version="1.0"?>
<!DOCTYPE library [
<!ENTITY foo "Some sentence...">
]>
<library xmlns="http://foo.com">
&foo;
</library>

But Xerces is saying that "library" element type is undefined. I can
understand that as library is defined in the "http://foo.com"
namespace. Does it means that it is impossible to use entities in
a document using schema/namespace?

If it is true, then it is impossible to split a large xml file into
several small files and then include them as external entites?

Thanks for any advice!

If I understand well, you don't want to do validation here at all.
Just suppress validation -- the parser will still read the DTD and
will correctly substitute the value of the entity for every occurence
of its entity reference.


Cheers,

Cheers,

Dimitre Novatchev [XML MVP],
FXSL developer, XML Insider,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
 
K

Kent Tong

(e-mail address removed) (Kent Tong) wrote in message If I understand well, you don't want to do validation here at all.
Just suppress validation -- the parser will still read the DTD and
will correctly substitute the value of the entity for every occurence
of its entity reference.

No, I am not trying to surpress validation. I want validation.

What I am trying to do is:
1. to introduce an entity to represent a long sentence that
would be used in many places.
2. to let different people work on different XML files and
then include the files into the main XML file.
 
D

Dimitre Novatchev

No, I am not trying to surpress validation. I want validation.

What I am trying to do is:
1. to introduce an entity to represent a long sentence that
would be used in many places.
2. to let different people work on different XML files and
then include the files into the main XML file.

Then you have to write the DTD to describe the structure of this
document type and the real names of the elements.

Unfortunately, DTD's are not namespace aware, therefore namespaces are
defined as attributes.

Here's the correct DTD for your document:

<!DOCTYPE library [
<!ENTITY foo "Some sentence...">
<!ELEMENT library (#PCDATA)>
<!ATTLIST library xmlns CDATA #FIXED
"http://foo.com" >

]>
<library xmlns="http://foo.com">
&foo;
</library>

You can check that now the validation is successful.

I'd greatly recommend a good book on XML -- the one that I have
recently read is:

"Effective XML, 50 Specific Ways to Improve Your XML", by Elliotte
Rusty Harold.

This is a great book that goes deep into many advanced topics of XML.


Hope this helped.


Cheers,

Dimitre Novatchev [XML MVP],
FXSL developer, XML Insider,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
 

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
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top