[英]PHP DOMDocument schemaValidate but get type
Sa我有两种类型的模式,一种用于<Request>
,另一种用于<Response>
。 我两个都有架构xsd。
我希望能够获得架构的“类型”,即使它是无效的也是如此。 例如, <Request to2="">...
应该无效,但是我仍然想知道这是一个Request
。
问题是如果属性也不正确, $xml->schemaValidate(...)
对于我的两个模式都将返回false
。
(此示例经过简化,实际上,对于每种模式类型,我可以有多个动词,因此,我不想遍历子节点并检查nodeType是什么)。
有没有一种方法可以使用DOMDocument仅验证选择(不验证属性)?
例如:
<Request>...</Request> ---> {type: 'Request', isValid: true},
<Response>...</Response> ---> {type: 'Response', isValid: true},
<Request to="api/action">...</Request> ---> {type: 'Request', isValid: true},
<Request tooo="api/action">...</Request> ---> {type: 'Request', isValid: false},
<Response type="json">...</Response> ---> {type: 'Response', isValid: true},
<Response typeeee="json">...</Response> ---> {type: 'Response', isValid: false},
如果我使用$xml->schemaValidate('/path/to/request.xsd');
和$xml->schemaValidate('/path/to/response.xsd');
我将无法分别确定<Request tooo="api/action">...</Request>
和<Response typeeee="json">...</Response>
因为它们是“无效”的
生成一个组合的XSD,根据它们的标签名称来验证这两种类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.