如何根据 soupUI 中的自定义 XSD 验证部分响应?

发布于 2024-12-27 06:22:13 字数 98 浏览 1 评论 0原文

在soapUI Pro 中,我想创建一个断言来根据自定义XSD 验证响应的指定XML 节点。我知道存在架构合规性断言,但我只想验证部分响应并针对自定义 XSD(不是来自 WSDL)。

In soapUI Pro I want to create an assertion to validate specified XML node of response against custom XSD. I know there is schema compliance assertion but I want to validate only part of response and against custom XSD (not from WSDL).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

要走干脆点 2025-01-03 06:22:13

需要脚本断言来加载部分响应并根据从文件加载的模式对其进行验证:

import com.eviware.soapui.support.XmlHolder
import javax.xml.XMLConstants
import javax.xml.transform.stream.StreamSource
import javax.xml.validation.SchemaFactory

def holder = new XmlHolder( messageExchange.responseContentAsXml )
holder.namespaces["sam"] = "http://www.example.org/sample/"
def node = holder["XPath"]

def factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
def schema = factory.newSchema(new StreamSource(new FileReader("path_to_XSD_file")))
def validator = schema.newValidator()
validator.validate(new StreamSource(new StringReader(node)))

Script assertion is needed to load part of response and validate it against schema loaded from file:

import com.eviware.soapui.support.XmlHolder
import javax.xml.XMLConstants
import javax.xml.transform.stream.StreamSource
import javax.xml.validation.SchemaFactory

def holder = new XmlHolder( messageExchange.responseContentAsXml )
holder.namespaces["sam"] = "http://www.example.org/sample/"
def node = holder["XPath"]

def factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
def schema = factory.newSchema(new StreamSource(new FileReader("path_to_XSD_file")))
def validator = schema.newValidator()
validator.validate(new StreamSource(new StringReader(node)))
醉南桥 2025-01-03 06:22:13

如果您已收到响应消息,请执行以下操作以仅验证响应的部分内容:

  • 切换到响应的表单视图。
  • 选择要检查的元素或节点。
  • 右键单击并选择您需要的断言。

您可以选择完整的节点或特定的元素和值。请点击此链接了解更多信息:
soapUI:验证 XML 消息

Providing you have received a response message do the following to validate only parts of the response:

  • Switch to the form view of the response.
  • Select the element or node you want to check.
  • Right-click and select the assertion you need.

You can select a complete node or specific elements and values. Follow this link for more information:
soapUI: Validating XML Messages

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文