Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Design a DTD

Status
Not open for further replies.

dvknn

IS-IT--Management
Mar 11, 2003
94
US
I am trying to design a DTD. I have a question.

I have 2 fields of which either of them should be present. For example:

X1 and X2 are the field anmes. Atleast one of them or both of them should be present.

How can I indicate that in the DTD design?

Thank You
 
by field anmes do you mean Elements?

looking for clarification
 
Here is how I would handle your situation as i understand it:

Code:
<?xml version=&quot;1.0&quot; ?>
<!DOCTYPE testXML [
<!ELEMENT testXML (( x1 | x2 ), x1?, x2? )>
<!ELEMENT x1 (#PCDATA) >
<!ELEMENT x2 (#PCDATA) >
]><testXML>
   <x2>some value</x2>
   <x1>some other value</x1>
</testXML>

hope this helps

by the by, you will notice that this will allow x1 and x2 to come in any sequence but only once.

 
huh?...
OK..This way, either x1 or x2 should be present (that is my requirement. either should be present). but, how can I restrict that x1 and x2 should follow a particular order??


<?xml version=&quot;1.0&quot; ?>
<!DOCTYPE testXML [
<!ELEMENT testXML (x1?, x2?, x3)>
<!ELEMENT x1 (#PCDATA) >
<!ELEMENT x2 (#PCDATA) >

Thanks,
 
Hello again!

Try this in your xml validator:

Code:
<?xml version=&quot;1.0&quot; ?>
<!DOCTYPE testXML [
<!ELEMENT testXML ( x1  | (x1 , x2) | x2 )>
<!ELEMENT x1 (#PCDATA) >
<!ELEMENT x2 (#PCDATA) >
]><testXML>
   <x1>some other value</x1>
   <x2>some value</x2>
</testXML>

depending on how loosly your validator follows the XML specification 1.0 appendix E, this will work.

here is a validator that accepts the definition:


and here is one that is very picky:

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top