0

JMeter で xsd スキーマに対して xml 応答を検証しようとしていますが、アサーションは常にエラーで失敗します

「ジョブ」を要素「コンテンツ」のタイプ定義に解決できません

xml 応答は次のとおりです。

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<result>
    <state>
        <tag>value</tag>
    </state>
    <content 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xsi:type="job">
        <status>ok</status>
    </content>
</result>

スキーマは次のとおりです。

<xs:schema attributeFormDefault="unqualified" 
           elementFormDefault="qualified" 
           xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="result">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="state">
          <xs:complexType>
            <xs:sequence>
              <xs:element type="xs:string" 
                          name="tag"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="content">
          <xs:complexType>
            <xs:sequence>
              <xs:element type="xs:string" 
                          name="status"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

応答は変更できませんが、スキーマは変更できます。どうすればこの問題を解決できますか?

ありがとう !

4

3 に答える 3

2

次のように XSD を変更する必要があります。

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified">
  <xs:element name="result">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="state">
          <xs:complexType>
            <xs:sequence>
              <xs:element type="xs:string" name="tag"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="content" type="content"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:complexType name="content">
  </xs:complexType>

  <xs:complexType name="job">
    <xs:complexContent>
      <xs:extension base="content">
        <xs:sequence>
          <xs:element type="xs:string" name="status"/>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

</xs:schema>

属性は、xsi:type階層を形成するさまざまなタイプを持つことができる要素の検証に使用するタイプの仕様として、検証によって特別な方法で処理されます。

上記の固定スキーマでは、基本content複合型とjobそれから派生した単純な階層を作成しました。

于 2013-08-01T12:47:25.477 に答える
0

応答を変更できないと言いますが、変更できます。検証する前に変換することができます。ここで行うのは正しいことかもしれません。xsi:type="job" が何を達成しようとしているのかわからないため、わかりません。

于 2013-08-01T12:48:11.683 に答える
0

Your response is refering to a type attribute defined as {http://www.w3.org/2001/XMLSchema-instance}:type. It does not belong to the namespace of your schema, hence you can't fix the validation by changing your schema.

In essence, the response is wrong (it refers to an unknown type in the w3 schema definition See the W3 schema definition here) so ideally the response should be fixed.

Edit after the comment:

If you could alter your response to have the type attribute in the same namespace of your response, something like:

<result xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <state>
        <tag>value</tag>
    </state>
    <content xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" type="job">
        <status>ok</status>
    </content>
</result>

Then it would validate with the following XSD:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:element name="result">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="state">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="tag" type="xs:string"/>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
                <xs:element name="content">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="status" type="xs:string"/>
                        </xs:sequence>
                        <xs:attribute name="type" type="type"/>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:simpleType name="type">
        <xs:restriction base="xs:string"/>
    </xs:simpleType>
</xs:schema>

You can then finetune the restrictions on your type to whatever you want.

于 2013-08-01T09:08:44.317 に答える