BizTalk Utilities CV ,   Jobs ,   Code library
 
Home Page


Add/Edit your code items
Search the code library
Browse for the code library


Schemas, xsd, xdr
The Loss of Formatting When Adding a Schema
simple xml notepad
Schemas using DBMS_XMLQuery Package
Tips for Designing a DTD - Part 1 of 4
Tips for Designing a DTD- Part 2 of 4 : Semi-Structured Documents
Tips for Designing a DTD- Part 3 of 4 : Database Oriented Data
Tips for Designing a DTD- Part 4 of 4 : Object Oriented Data
Getting the value of an element with optional subelements
XML Code Generator: Generating Wrapper Classes from an XML Schema
What is WDDX?
XSLT Stylesheet for summarizing the structure of an XML document
Validating XML with Schemas
Punctuated Changes In XML Documents
XMLStarlet Command Line XML Toolkit
W2XML v2.0 SR1
Free DTD for Academic Publishers
Arquemie for XML Schemas
XMLStarlet Command Line XML/XSLT Toolkit
XSD Merger


 
 

<< reBloggerSEO >>


By Robert Kviby
First Posted 08/29/2001
Times viewed 2175

Entity name support without DTDs


Summary To get entity name support you need to use a DTD, however you can get a similar effect using XML elements and a Schema.

Recently I bumped into the following problem:

I was working with a set of XML-files that referenced to a complex DTD file. Since, in that application, I rather use schemas I rewrote the DTD and “made it into” a schema. However, I made one mistake; I forgot to check if entities are supported in schemas as well as in DTD’s. Pretty soon I discovered that wasn’t the case. My &mdash;, &ndash; and &hellip; stayed undeclared and that made the use of my application impossible.

The big question is: do you have to use a DTD to get entity name support in an XML-file? The simple answer is: yes, the only way is to have either an internal or external DTD and declare the entities within it.

XML provides entities that are named fragments of content that can be used in the construction of DTD's and instance documents. But isn’t Schemas supposed to make DTD’s obsolete? No. The purpose of W3C is not to replace the DTDs with the WC3 XML Schema; DTDs include 4 features:

1) Macro instructions
2) Inclusions
3) Linking
4) Schema

And the purpose of W3C XML Schema is to replace item 4.  Hence, DTDs are here to stay for, at least, a foreseeable future.

But if I want to use a schema and not a DTD, how can I get the equivalent of entity name support in my XML-files? I’ll show you below.

toc.xml contains a short table of contents containing the entities &dash; and &hellip;. If we should use a DTD to declare the entities it would look like this:

toc.xml
<?xml version=1.0?>
<!DOCTYPE note SYSTEM toc.dtd>

<toc title=Savy Articles>
  <item identifier=1>Managing the Whitespace &ndash; An Art</item>
  <item identifier=2>Strong Sales by Focus on Training</item>
  <item identifier=3>The For Each&hellip;Next Loop</item>
</toc>

Here, we declare the entities as in an external DTD, and we reference the entities in the content of the first and third item element. The DTD looks like this:

toc.dtd
<!ELEMENT toc (item)>
<!ELEMENT item (#pcdata)>

<!ATTLIST toc title cdata>
<!ATTLIST item identifier cdata>

<!ENTITY ndash - >
<!ENTITY hellip ...>

Luckily for those developers that want to work only with schemas, we can achieve a similar outcome by declaring an element in a schema and setting the element’s content as follows:

tocschema.xml
<?xml version=1.0 encoding=iso-8859-1?>

<Schema name=toc xmlns=urn:schemas-microsoft-com:xml-data
                    xmlns:dt=urn:schemas-microsoft-com:datatypes>

<AttributeType name=title required=yes dt:type=string/>
<AttributeType name=identifier required=yes dt:type=string/>

<ElementType name=toc dt:type=string>
    <attribute type=title/>
    <element type=item minOccurs=1 maxOccurs=*/>
</ElementType>

<ElementType name=item dt:type=string>
    <attribute type=identifier/>
</ElementType>

<dt:element name=ndash type=dt:token fixed= - />
<dt:element name=hellip type=dt:token fixed=.../>

</Schema>

And, instead of entities, we use elements in the XML-file:

<toc title=Savy Articles xmlns:dt=x-schema:tocschema.xml>
  <item identifier=1>Managing the Whitespace <dt:ndash/> An Art</item>
  <item identifier=2>Strong Sales by Focus on Training</item>
  <item identifier=3>The For Each <dt:hellip/> Next Loop</item>
</toc>

In this case the schema processor will process the item element and the ndash and hellip elements separately and for the ndash and hellip element simply supply “ – “ for the former and “…” for the latter.

Thanks you for your time!

Robert Kviby
Binary Bros - FREE BOOKS AND ARTICLES ON NGCODE.COM!

Additional information


Rate this article on a scale of 1 to 10 (0 votes, average 0)

Your vote :  

<< reBloggerSEO >>





Leave a comment for this article
Your name
Your email (optional)
Your comment
Optional: Upload an attachment
Enter the code shown:

 
 

    Email TopXML