Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

How we can do Datatype assertion in Xml assertor?

jyoti
jyoti Posts: 2

I tried in json assertor-there is type assertion but xml assertor doesnt have.

Comments

  • benken_parasoft
    benken_parasoft Posts: 1,309 ✭✭✭
    edited August 2024

    Are you trying to check the type of node matched by your XPath, like whether it is an Element or Attribute or Text? JSON's concepts of types (object, array, string, number, etc.) are very different and do not apply to XML.

  • jyoti
    jyoti Posts: 2
    edited August 2024

    So there is no way to check like whether the element returned is string or number?

  • benken_parasoft
    benken_parasoft Posts: 1,309 ✭✭✭
    edited August 2024

    In XML, text nodes are just text. An XML document does not necessarily say whether the consumer should interpret the text node as a string or a number or a date or a phone number or something else. In JSON, there is different syntax for strings vs numbers (for example) but in XML there is no such thing.

    In contrast, an XML schema (.xsd document) defines the type and allowed structure of each node in the document. If you have an XML schema then you can use the XML Validator tool to check whether the XML document conforms to the schema. For example, if the XML schema document says a particular text node is supposed to be a number but contains a letter then the XML Validator tool will report a violation. The XML Validator tool can also be provided a WSDL if the XML being validated is a SOAP envelope.

    On this topic, JSON documents can also be defined by a JSON schema. A JSON schema can say things like what properties are expected for a particular object and their expected types. The JSON Validator tool can similarly be used to validate whether a JSON document conforms to its schema. An OpenAPI service definition document can also be provided which is common if you are validating the response from a REST API.