1

I am having problems using a schema in either DTD or XSD format to validate XML returned to JMeter.

The error code I am getting is this.

Assertion error: true
Assertion failure: false
Assertion failure message: error: line=1 col=71 schema_reference.4: Failed to read schema document 'schema.dtd', because 
1) could not find the document; 
2) the document could not be read; 
3) the root element of the document is not <xsd:schema>.

I have made sure the schema is in this same location as the Jmeter test and is not read only etc.

Sample DTD

<!ELEMENT userId (#PCDATA)>
<!ELEMENT recordId (#PCDATA)>
<!ELEMENT operationDateTime (#PCDATA)>
<!ELEMENT operationCode (#PCDATA)>
<!ELEMENT oldVal (#PCDATA)>
<!ELEMENT newVal (#PCDATA)>
<!ELEMENT listOfAuditItems ((auditItem))>
<!ELEMENT fieldName (#PCDATA)>
<!ELEMENT buscomp (#PCDATA)>
<!ELEMENT auditItem ((recordId, userId, operationCode, buscomp, operationDateTime, fieldName, oldVal, newVal))>
<!ELEMENT ariResponse ((listOfAuditItems))>

I checked the validity of the DTD file here and it passed!

Sample XML

    <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
    <ariResponse>
        <listOfAuditItems>
            <auditItem>
                <recordId>2-1DFSGT</recordId>
                <userId>1-1SJKJS</userId>
                <operationCode>Modify</operationCode>
                <buscomp>Service Request</buscomp>
                <operationDateTime>2010-05-12T15:23:53.000+05:30</operationDateTime>
                <fieldName />
                <oldVal />
                <newVal />
                <auditLog>2*C311*EVT_STAT_CD16*TODO_PLAN_END_DT11*OWNER_LOGIN2*N34*Open19*2011-01-06
                    16:28:567*RITESHP2*O30*0*0*
                </auditLog>
            </auditItem>
        </listOfAuditItems>
        <returncode>0</returncode>
        <errormessage />
    </ariResponse>

Thanks!

UBIK LOAD PACK
  • 33,980
  • 5
  • 71
  • 116
tomaytotomato
  • 3,788
  • 16
  • 64
  • 119

1 Answers1

0

Summary: in the end I've used http://path.to.schema/myschema.xsd as the File Name parameter in the Assertion.

Explanation: following Alies Belik's advice, I've found that the code for setting up the schema looks something like this:

DocumentBuilderFactory parserFactory = DocumentBuilderFactory.newInstance();
...
parserFactory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", xsdFileName);

where xsdFileName is a string (the attribute string is actually a constant, I inlined it for readability).

According to e.g. this page, the attribute, when in the form a String, is interpreted as an URI - which includes HTTP URLs. Since I already have the schema accessible through HTTP, I've opted for this solution.

tomaytotomato
  • 3,788
  • 16
  • 64
  • 119