Re: question

Hi,

> DTD provide internal & external ENTITY reference function
> So XML instant document which using DTD can insert external XML instant
> for ENTITY declaration
>
> ex)
> <?xml version="1.0" encoding="euc-kr"?>
> <!DOCTYPE testobject1 SYSTEM "file:///c:/record.dtd"[
> <!ENTITY testobject2 SYSTEM "file:///c:/testobject2.xml"
> >]>
> <biblio>
> &testobject2;
> </biblio>
>
> But I think XML schema has not ENTITY Declaration
> So the instant XML document which use XML schema
> can not insert external ENTITY.
>
> In XML Schema, is there some funtion like external ENTITY declaration as DTD ?

XML Schema don't support entities and there is no function in XML Schema that is
similar to external entities in DTDs. However, since an XML Schema processor work
on the XML Infoset and not on the instance document itself you can still use a DTD
as well as a schema. If you then you external entities these will be resolved
during the DTD validation (if that's the option you have chosen in your XML
processor).
If you use external entities (like in your example above) then you dtd
(file:///c:/record.dtd) must contain all the element/attribute declarations for
your instance document otherwise you will get an when DTD validation is performed.
At least this is the way I think it works...

I've done some testing using external entities with XSV and XML Spy and I'm
confused about the behaviour. Say that I have simple XML Schema:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
 <xs:complexType name="PhysicalAddress_Type">
  <xs:sequence>
   <xs:element name="Street" type="xs:string"/>
   <xs:element name="State" type="xs:string"/>
   <xs:element name="Country" type="xs:string"/>
  </xs:sequence>
 </xs:complexType>
 <xs:element name="PhysicalAddress" type="PhysicalAddress_Type"/>
</xs:schema>

And then I have an instance that is divided into two documents where the first
document is the street fragement:

street.xml
----------
<?xml version="1.0" encoding="UTF-8"?>
<Street>Pyrmont Street</Street>

and a the main document:

physicaladdress.xml
--------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE PhysicalAddress [
 <!ENTITY street SYSTEM "street.xml">
]>
<PhysicalAddress xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="PhysicalAddress.xsd">
 &street;
 <State>NSW</State>
 <Country>Australia</Country>
</PhysicalAddress>

If I run this through XSV and XML Spy both accept the instance without reporting
any errors. The XML Rec says [1]:

"When an XML processor recognizes a reference to a parsed entity, in order to
validate the document, the processor must include its replacement text. If the
entity is external, and the processor is not attempting to validate the XML
document, the processor may, but need not, include the entity's replacement text.
If a non-validating processor does not include the replacement text, it must
inform the application that it recognized, but did not read, the entity."

Since both XSV and XML Spy validate this without any errors I guess the XML
processor they're using resolves the external entity without actually doing any
validation. Correct?
On the other hand if I run this with MSXML4 I will get an error because the
external entity is only resolved if DTD validation is used and if DTD validation
is used I will get errors because the DTD dosn't contain any element declarations.
So, in conslusion, if I want to be able to use external entities in this way
together with XML Schema that should work on all processors then the DTD must
contain all the element/attribute declarations.

In my example this would be:

physicaladdress.xml
--------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE PhysicalAddress [
 <!ENTITY street SYSTEM  "street.xml">
 <!ELEMENT PhysicalAddress (Street, State, Country)>
 <!ATTLIST PhysicalAddress xmlns:xsi CDATA #IMPLIED
                                               xsi:noNamespaceSchemaLocation CDATA
#IMPLIED>
 <!ELEMENT Street (#PCDATA)>
 <!ELEMENT State (#PCDATA)>
 <!ELEMENT Country (#PCDATA)>
]>
<PhysicalAddress xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="PhysicalAddress.xsd">
 &street;
 <State>NSW</State>
 <Country>Australia</Country>
</PhysicalAddress>

Is this a correct understanding on my part or have I missed something?

Cheers,
/Eddie

[1] http://www.w3.org/TR/2000/REC-xml-20001006#include-if-valid

Received on Thursday, 5 July 2001 20:26:11 UTC