Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[wtp-dev] Should WTP DOM be Content Model Aware

While looking at some more improvements for the WTP DOM compliance against the W3C DOM Test suite, I ran into a few tests where the DOM needs to be grammar aware. In particular when testing for the existance of default attributes and their values. As an example:

Staff.dtd

<!ELEMENT employeeId (#PCDATA)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT position (#PCDATA)>
<!ELEMENT salary (#PCDATA)>
<!ELEMENT address (#PCDATA)>
<!ELEMENT entElement ( #PCDATA ) >
<!ELEMENT gender ( #PCDATA | entElement )* >
<!ELEMENT employee (employeeId, name, position, salary, gender, address) >
<!ELEMENT staff (employee)+>
<!ATTLIST entElement
          attr1 CDATA "Attr">
<!ATTLIST address
          domestic CDATA #IMPLIED
          street CDATA "Yes">
<!ATTLIST entElement
          domestic CDATA "MALE" >

Staff.xml

<staff>
<employee>
<employeeId>EMP0001</employeeId>
<name>Margaret Martin</name>
<position>Accountant</position>
<salary>56,000</salary>
<gender>Female</gender>
<address domestic="Yes">1230 North Ave. Dallas, Texas 98551</address>
</employee>
</staff>

Their is a test that gets all the Attributes for the address element, and then tries to retrieve the street attribute. However, WTP fails this test, since it returns Null when getNamedItem("street") is called.

    Document doc;
      NodeList addressList;
      Node testNode;
      NamedNodeMap attributes;
      Attr streetAttr;
      String value;
      doc = (Document) load("staff", false);
      addressList = doc.getElementsByTagName("address");
      testNode = addressList.item(0);
      attributes = testNode.getAttributes();
      streetAttr = (Attr) attributes.getNamedItem("street");
      assertNotNull("attrDefaultValueAssert", streetAttr);
      value = streetAttr.getNodeValue();
      assertEquals("attrDefaultValueAssert", "Yes", value);

The W3C test expects the following:

1. that default attributes are returned if they aren't specified on the element.
2. that the value is set to the default value.

The question is do we want to add the ability for the WTP DOM to be content model aware if their is a Schema or DTD specified?

Dave






Back to the top