how to create a dtd for this xml?
i have been asked to create a simple dtd for this xml :
<?xml version='1.0' encoding='ISO-8859-1'?>
<QUERY>
<PORT>
<NB></NB>
</PORT>
<BLOCK>
<TAB></TAB>
</BLOCK>
<STAND>
<LEVEL></LEVEL>
</STAND>
</QUERY>
i am using java, i've never did dtd before nor do i know precisely what does it mean. i would like some guid开发者_JAVA技巧ance if its possible, thank you
DTD is Document Type Definition, and is used to represent the structure of you XML document. Other representations include XML Schema, Relax NG, etc.:
- http://en.wikipedia.org/wiki/Document_Type_Definition
It will look something like the following (although my syntax may not be quite right):
<!ELEMENT QUERY (PORT, BLOCK, STAND)>
<!ELEMENT PORT (NB)>
<!ELEMENT NB (#PCDATA)>
<!ELEMENT BLOCK (TAB)>
<!ELEMENT TAB (#PCDATA)>
<!ELEMENT STAND (LEVEL)>
<!ELEMENT LEVEL (#PCDATA)>
If you look at the definition for QUERY you see it defines that it contains the elements: "PORT", "BLOCK", and "STAND". If you look at the definition for NB, we have declared that it should contain text (parsed character data).
XMLBeans comes with a tool called inst2xsd
which can inspect an XML file and create an XSD for it that you can then edit/refine. I've used it with pretty good results.
Just read the installation guide for XMLBeans and when you install XMLBeans you'll have the inst2xsd
tool installed as well.
edit - just realized you wanted a DTD and not an XSD, leaving this here in case an XSD (which is very similar in purpose) could actually solve your problem anyway
There are some DTD generators out there. Quick search yields this. Haven't used it, though.
精彩评论