[英]PHP DOMDocument schemaValidate but get type
Sa I have two types of schemas, one for <Request>
and one for <Response>
. Sa我有两种类型的模式,一种用于
<Request>
,另一种用于<Response>
。 I have the schema xsd for both. 我两个都有架构xsd。
I want to be able to get the "type" of the schema, even if it is invalid. 我希望能够获得架构的“类型”,即使它是无效的也是如此。 For example,
<Request to2="">...
should be invalid, but I want to still know that this is a Request
. 例如,
<Request to2="">...
应该无效,但是我仍然想知道这是一个Request
。
The problem is $xml->schemaValidate(...)
will return false
for both of my schemas if the attributes are also wrong. 问题是如果属性也不正确,
$xml->schemaValidate(...)
对于我的两个模式都将返回false
。
(this example is simplified, in reality, I can have multiple verbs for each schema types, so I don't want to iterate through the child nodes and check what the nodeType is). (此示例经过简化,实际上,对于每种模式类型,我可以有多个动词,因此,我不想遍历子节点并检查nodeType是什么)。
Is there a way to use DOMDocument to validate the choice only (no attribute validation)? 有没有一种方法可以使用DOMDocument仅验证选择(不验证属性)?
For instance: 例如:
<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},
If I juse use $xml->schemaValidate('/path/to/request.xsd');
如果我使用
$xml->schemaValidate('/path/to/request.xsd');
and $xml->schemaValidate('/path/to/response.xsd');
和
$xml->schemaValidate('/path/to/response.xsd');
I will not be able to determine the type of <Request tooo="api/action">...</Request>
and <Response typeeee="json">...</Response>
respectively because they are "invalid" 我将无法分别确定
<Request tooo="api/action">...</Request>
和<Response typeeee="json">...</Response>
因为它们是“无效”的
生成一个组合的XSD,根据它们的标签名称来验证这两种类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.