Wednesday, June 21, 2006

Multiple DTD in xml and namespace workaround in DTD

Following xml fragments will give an idea of how to use multiple dtd's in xml and also the workaround of specifying namespace in dtd

File : s.dtd
============
<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT computer (ns1:address) >
<!ELEMENT ns1:address (type, ipaddress)>
<!ELEMENT type (#PCDATA)>
<!ELEMENT ipaddress (#PCDATA)>

File : s1.dtd
==============
<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT ns2:student (name, ns2:address, computer) >
<!ATTLIST ns2:student xmlns:ns2 CDATA #FIXED "http://krishna/ns2">
<!ELEMENT ns2:address (#PCDATA) >
<!ELEMENT name (#PCDATA) >

File:student.xml
================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ns2:student SYSTEM "s1.dtd" [<!ENTITY % s SYSTEM "s.dtd">
%s;
]>
<ns2:student xmlns:ns2="http://krishna/ns2">
<name >krishna</name>
<ns2:address>unknown</ns2:address>
<computer>
<ns1:address>
<type></type>
<ipaddress></ipaddress>
</ns1:address>
</computer>
</ns2:student>

1 comment:

Anonymous said...

Hi Krishna,

Nice to see your blog. You could use Jroller for Java or tech blogs.

- Hardik
http://www.jroller.com/page/hardik_tank