0% found this document useful (0 votes)
62 views

!doctype Application Public "-//sun Microsystems, Inc.//Dtd J2Ee Application

A DOCTYPE declaration can contain the name of the document root element, system and public identifiers for validating the document structure against a DTD, and an internal subset of DTD declarations within square brackets. A DOCTYPE declaration is mandatory for validation and must identify a DTD that corresponds to the document structure. Nonvalidating parsers will accept documents without a DOCTYPE declaration.

Uploaded by

dvsindhuri
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views

!doctype Application Public "-//sun Microsystems, Inc.//Dtd J2Ee Application

A DOCTYPE declaration can contain the name of the document root element, system and public identifiers for validating the document structure against a DTD, and an internal subset of DTD declarations within square brackets. A DOCTYPE declaration is mandatory for validation and must identify a DTD that corresponds to the document structure. Nonvalidating parsers will accept documents without a DOCTYPE declaration.

Uploaded by

dvsindhuri
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

A DOCTYPE declaration can contain:

 The name of the document or root element.

This is required if the DOCTYPE declaration is used.

 System and public identifiers for the DTD that can be used to validate the document
structure.

If a public identifier is used, a system identifier must also be present.

 An internal subset of DTD declarations.

The internal subset appears between square brackets ([ ]).

A DOCTYPE declaration is mandatory if the document is to be processed in a validating


environment. To be valid, the DOCTYPE declaration must identify a DTD that corresponds to
the document structure of the document. Nonvalidating parsers will accept documents without
DOCTYPE declarations.

The simplest DOCTYPE declaration identifies only the root element of the document.

<!DOCTYPE rootElement>

More often, documents that use the DOCTYPE declaration reference an external document
containing the declarations that make up the DTD. The following can be used to identify the
external DTD.

<!DOCTYPE rootElement SYSTEM "URIreference">

The URIreference points to a file containing the declarations.

<!DOCTYPE rootElement PUBLIC "PublicIdentifier" "URIreference">

<!DOCTYPE application PUBLIC "-//Sun Microsystems, Inc.//DTD J2EE Application


1.3//EN" "http://java.sun.com/dtd/application_1_3.dtd">

The PublicIdentifier provides a separate identifier that some XML parsers can use to
reference the DTD in place of the URIreference. This is useful if the parser is used on a system
without a network connection or where that connection would slow down processing
significantly.

DOCTYPE declarations can also include declarations directly, in what is referred to as the
internal subset. If a DOCTYPE declaration includes the entire DTD directly, without reference to
external files, it uses the following syntax.
<!DOCTYPE rootElement [
declarations
]>

If the DOCTYPE declaration includes declarations that are to be combined with external files or
the external subset, it uses the following syntax.

<!DOCTYPE rootElement SYSTEM "URIreference"[


declarations
]>

or

<!DOCTYPE rootElement PUBLIC "PublicIdentifier" "URIreference"[


declarations
]>

URI :

One can classify URIs as locators (URLs), or as names (URNs), or as both. A Uniform Resource Name
(URN) functions like a person's name, while a Uniform Resource Locator (URL) resembles that person's
street address. In other words: the URN defines an item's identity, while the URL provides a method for
finding it.

XML Namespaces, Prefixes, and elementFormDefault


Note: The GeeksWithBlogs editor seems to keep really messing with the formatting / XML of
this post. If you spot any errors, please hit the Contact Me link above and I'll try to wrestle it
into submission again :-)

This entry may be useful to people confused by BizTalk's inclination to "ns0" at the drop of a hat
:-)

Someone asked me today why their XML document wasn't validating. They thought that it was
because the schema was expecting messages with a default namespace of "uri:my-namespace"
but the document they were validating instead defined all the nodes using a prefix of "ns0", with
ns0 mapping to uri:my-namespace.
One of the biggest misunderstandings in XML is namespaces. There's absolutely no difference to
an xml parser or to the interpretation of a document whether you use a prefix on every node, or a
default namespace. Prefixes are only a syntactic abbreviation. In other words:

<mydoc xmlns="uri:my-namespace">
    <subnode />
</mydoc>
(Default namespace flows into the child - there is no prefix, so it uses the default
namespace)

is identical to:

  <ns0:mydoc xmlns:ns0="uri:my-namespace">
    <ns0:subnode xmlns:ns1="uri:my-namespace" />
</ns0:mydoc>
(The prefix ns0 maps to uri:my-namespace, and both nodes are marked with ns0)

and to:

<ns0:mydoc xmlns:ns0="uri:my-namespace">
    <ns1:subnode xmlns:ns1="uri:my-namespace" />
</ns0:mydoc>
(No default namespace, but ns0 and ns1 both map to uri:my-namespace and hence have
identical meaning)
 
and
 
<ns0:mydoc xmlns:ns0="uri:my-namespace">
   <subnode xmlns="uri:my-namespace" />
</ns0:mydoc>

(ns0 is defined on the parent, but we then set a default namespace for this node - and any
children, if it had any)

In all of the cases above, the namespace of subNode is uri:my-namespace.

It turned out in the end that the problem was that the schema defined the namespace as "uri:my-
namespace" but the result document was coming back with a namespace of "uri:my-namespace/"
- the trailing slash being all important. Remember folks, namespaces are just strings - a trailing
slash may not make a difference to most Internet browsers, but they do in XML Schema.

ElementFormDefault
As a bonus, a little note on elementFormDefault.
 
If in your schema you use elementFormDefault="qualified" then you can validate all of the
documents above with a schema similar to (pseudo-code): 
<xs:schema targetNamespace="uri:my-namespace" elementFormDefault="qualified">
   <xs:element name="myDoc">
      <xs:complexType>
         <xs:sequence>
            <xs:element name="subnode" maxOccurs="1" />
         </xs:sequence>
      </xs:complexType>
   </xs:element>
</xs:schema>

If you changed the elementFormDefault to "unqualified" then instead it would only look for the root element to be in
the namespace, and child elements would be unqualified (in the empty namespace):

<ns0:mydoc xmlns:ns0="uri:my-namespace">
  <subnode/>
</ns0:mydoc>

and

 
<ns0:mydoc xmlns:ns0="uri:my-namespace">
   <ns1:subnode xmlns:ns1=""/>
</ns0:mydoc>
(An explicitly empty prefixed namespace definition)
 
and

<ns0:mydoc xmlns:ns0="uri:my-namespace">
   <subnode xmlns=""/>
</ns0:mydoc>
(An explicitly empty default namespace definition for the sub node, and its child nodes if it had any)

I was lucky enough to learn about Namespaces on a Developmentor training course run by Aaron Skonnard ages
ago so thanks to him for the foundations of this entry :-)

XML Namespaces
« Previous Next Chapter »

XML Namespaces provide a method to avoid element name conflicts.

Name Conflicts
In XML, element names are defined by the developer. This often results in a conflict when trying
to mix XML documents from different XML applications.
This XML carries HTML table information:

<table>
  <tr>
    <td>Apples</td>
    <td>Bananas</td>
  </tr>
</table>

This XML carries information about a table (a piece of furniture):

<table>
  <name>African Coffee Table</name>
  <width>80</width>
  <length>120</length>
</table>

If these XML fragments were added together, there would be a name conflict. Both contain a
<table> element, but the elements have different content and meaning.

An XML parser will not know how to handle these differences.

Solving the Name Conflict Using a Prefix


Name conflicts in XML can easily be avoided using a name prefix.

This XML carries information about an HTML table, and a piece of furniture:

<h:table>
  <h:tr>
    <h:td>Apples</h:td>
    <h:td>Bananas</h:td>
  </h:tr>
</h:table>

<f:table>
  <f:name>African Coffee Table</f:name>
  <f:width>80</f:width>
  <f:length>120</f:length>
</f:table>

In the example above, there will be no conflict because the two <table> elements have different
names.

XML Namespaces - The xmlns Attribute


When using prefixes in XML, a so-called namespace for the prefix must be defined.

The namespace is defined by the xmlns attribute in the start tag of an element.

The namespace declaration has the following syntax. xmlns:prefix="URI".

<root>

<h:table xmlns:h="http://www.w3.org/TR/html4/">
  <h:tr>
    <h:td>Apples</h:td>
    <h:td>Bananas</h:td>
  </h:tr>
</h:table>

<f:table xmlns:f="http://www.w3schools.com/furniture">
  <f:name>African Coffee Table</f:name>
  <f:width>80</f:width>
  <f:length>120</f:length>
</f:table>

</root>

In the example above, the xmlns attribute in the <table> tag give the h: and f: prefixes a qualified
namespace.

When a namespace is defined for an element, all child elements with the same prefix are
associated with the same namespace.

Namespaces can be declared in the elements where they are used or in the XML root element:

<root
xmlns:h="http://www.w3.org/TR/html4/"
xmlns:f="http://www.w3schools.com/furniture">

<h:table>
  <h:tr>
    <h:td>Apples</h:td>
    <h:td>Bananas</h:td>
  </h:tr>
</h:table>

<f:table>
  <f:name>African Coffee Table</f:name>
  <f:width>80</f:width>
  <f:length>120</f:length>
</f:table>

</root>

Note: The namespace URI is not used by the parser to look up information.

The purpose is to give the namespace a unique name. However, often companies use the
namespace as a pointer to a web page containing namespace information.

Try to go to http://www.w3.org/TR/html4/.

You might also like