Hello Everyone.
I'm new to XML and was trying to get my first DTD configured. I could not find an example of a constraint on the value of a node using the DTD. [All examples point to attributes with contraints. Maybe I should try harder to find one example...]
I'm trying to build a very simple DTD (as a learning exercise) for a list of machines. The only data contained in the XML file is machine name and platform. I want to restrict the value of the platform to either "Windows" or "Unix" and not go for attributes.
This XML file when loaded in IE6 browser gives no error. However, if I change the "Platform" value to "Unix1", I want it to throw an error. Can someone kindly help me put the right constraint on the element value ?
I'm new to XML and was trying to get my first DTD configured. I could not find an example of a constraint on the value of a node using the DTD. [All examples point to attributes with contraints. Maybe I should try harder to find one example...]
I'm trying to build a very simple DTD (as a learning exercise) for a list of machines. The only data contained in the XML file is machine name and platform. I want to restrict the value of the platform to either "Windows" or "Unix" and not go for attributes.
Code:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!DOCTYPE MachineList [
<!ELEMENT MachineList (Machine)*>
<!ELEMENT Machine (MachineName,Platform)>
<!ELEMENT MachineName (#PCDATA)>
<!ELEMENT Platform (Windows | Unix)>
]>
<MachineList>
<Machine>
<MachineName>Harsh</MachineName>
<Platform>Unix</Platform>
</Machine>
<Machine>
<MachineName>Vedh</MachineName>
<Platform>Windows</Platform>
</Machine>
</MachineList>
Comment