XML模式验证 [英] XML schema validation

查看:80
本文介绍了XML模式验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试针对一个架构验证XML文件,而我通常可以毫无问题地实现该架构,但是,在此特定架构中,存在导入的名称空间,这似乎阻止了验证的进行,因为返回的错误指向到导入的xsd中元素的节点.

我可以手动输入XML文件的子元素的名称空间引用,它会正确验证,但是我无法通过代码验证文档.


我已经尝试了很多方法,但都无济于事:

我已将多个XSD添加到XMLSchemaSet中,该XSD返回了重复的声明问题.我认为这是由于顶层架构导入了第二个XMLSchema.

我还在声明中尝试了导入< xmlns ="2nd_namespace"> ;,但这似乎无济于事.

我也一直试图将名称空间应用于我可以手动更新的子元素.当针对所应用的架构对xDoc进行验证时,它会覆盖先前正确的元素所应用的名称空间.



我可以添加多个架构吗?我做错什么了吗?
在验证模式期间,我可以强制执行某些操作吗?

Hi,

I am trying to validate an XML file against a schema, which i can achieve without issue normally, however, in this particular schema, there is an imported namespace, that appears to be preventing the validation from happening, as the error being returned is pointing to node of the elements from the imported xsd.

I can manually enter the namespace refrences to the child elements of the XML file and it will validate correctly, however I cannot validate the document, by way of the code.


I have tried a number of things all to no avail:

I have added multiple XSD''s to the XMLSchemaSet, which returned a duplicate declaration issue. I assume this is due to the top level schema having an import of the 2nd XMLSchema.

I also tried imports <xmlns="2nd_namespace">, within the declarations, but this seemed to do nothing.

I have also been attempting to apply a namespace to the child elements that I can update manually. When the xDoc is validated against the applied schema it overwrites the previously correct element applied namespaces.



Can I add multiple schemas? am i doing something wrong?
Can i force something in during the validation of a schema.

Any advice would be appreciated here guy''s.

推荐答案

使用以下xsl剥离多个名称空间:
Use the following xsl to strip off multiple namespaces:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="no" />
  <xsl:template match="/|comment()|processing-instruction()">
    <xsl:copy>
      <xsl:apply-templates />
    </xsl:copy>
  </xsl:template>
  <xsl:template match="*">
    <xsl:element name="{local-name()}">
      <xsl:apply-templates select="@*|node()" />
    </xsl:element>
  </xsl:template>
  <xsl:template match="@*">
    <xsl:attribute name="{local-name()}">
      <xsl:value-of select="." />
    </xsl:attribute>
  </xsl:template>
</xsl:stylesheet>



您可以使用XslCompiledTransform转换xml文件,然后将其用于验证.还请记住创建没有多个名称空间的xsd.



You can use XslCompiledTransform to transform your xml file, then use it for validation. Also remember to create xsd without multiple namespaces.


感谢您的响应,非常有趣的一点将在以后尝试.我设法通过将实际上是3种不同的名称空间强制设置为XML文档的适当结构来解决此问题.
整个根名称空间一直覆盖着XSD上的所有其他名称空间,直到我删除了该名称空间,然后在以后重新添加它(针对模式进行了验证).

再次感谢.
Thank you for the response, very interesting will give it a try at a later date. I have managed to resolve this by forcing what was actually 3 differing namespace to the appropriate structures of the XML doc.
The overall root namespace had been overriding all others on the XSD until I removed then re-added at a later point, pre valiation against schema.

Thanks again.


这篇关于XML模式验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆