Contraints on value of node using DTD

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • paragpdoke
    New Member
    • Dec 2007
    • 62

    Contraints on value of node using DTD

    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.

    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>
    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 ?
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    I think IE6 either is not validating the DTD, or even if it is aware of the error displays the information anyways.

    I'm not sure you can get it to throw an error unless you force it to validate.

    Comment

    • paragpdoke
      New Member
      • Dec 2007
      • 62

      #3
      Hello jkmyoung.
      Thanks for looking into this. I tried loading the same XML file (with "Unix11" instead of "Unix") in Firefox, Opera too. However, none of them displayed errors. So I guess I'm doing something wrong.

      Just guessing...mayb e one cannot force a constraint on the node values from a DTD ? If such a thing is possible, can someone help me with an example ?
      No matter how much I search, I keep finding contraints on the attribute values only.

      Thanks in advance again,
      Parag P. Doke

      Comment

      Working...