xml - 如何使用 apache camel 验证 xsd?

标签 xml validation xsd apache-camel apache-karaf

我正在使用 apacheservicemix 并尝试使用 apache camel 验证 xml 文档。我有一条名为 students_route.xml 的路线:

<?xml version="1.0" encoding="UTF-8"?>
<blueprint
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
  http://www.osgi.org/xmlns/blueprint/v1.0.0
  http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<route>
    <from uri="file:project/students.xml"/>
    <doTry>
    <to uri="validator:file:project/students.xsd"/>
    <to uri="file:valid"/>
    <doCatch>
        <exception>org.apache.camel.ValidationException</exception>
        <to uri="file:invalid"/>
    </doCatch>
    <doFinally>
        <to uri="file:finally"/>
    </doFinally>
    </doTry>
</route>
</camelContext>
</blueprint>

我创建了 3 个目录:valid、invalid 和 finally。 在我运行 karaf“start students_route.xml”后,什么也没有发生。当我查看日志时,我没有收到任何错误,只是收到了一些这样的消息:“路由:route2 开始并使用来自:端点 [file://project/students.xml]”。我想应该在有效/无效下创建一个文件xml 文件是否有效的目录。

我是这项技术的新手,我不知道如何让它发挥作用。我将衷心感谢您的帮助。提前致谢!

最佳答案

这是一个工作示例:

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:camel="http://camel.apache.org/schema/blueprint"
       xsi:schemaLocation="
       http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
       http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/spring/camel-blueprint.xsd">

  <camelContext xmlns="http://camel.apache.org/schema/blueprint">
      <route>
          <from uri="file:flights/data-in?noop=false"/>
          <doTry>
              <to uri="validator:file:flights/schema/flight.xsd"/>
              <to uri="file:flights/data-valid"/>
              <doCatch>
                  <exception>org.apache.camel.ValidationException</exception>
                  <to uri="file:flights/data-invalid"/>
              </doCatch>
              <!--
              <doFinally>
                  <to uri="file:test/src/data/finally"/>
              </doFinally>
              -->
          </doTry>
      </route>

  </camelContext>

</blueprint>

玩得开心!

关于xml - 如何使用 apache camel 验证 xsd?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28263085/

相关文章:

c# - 使用 XDocument 计算子元素的数量

android - 旋转图层列表中的项目以显示启动画面

java - CXF wsdl2java - 生成不带包装器的列表(静态内部类)

c# - 根据 XSD 验证 XML 并忽略子元素的顺序

xml - "XML Roundtrip"对 Word 2003 文档有何影响?

java - 评估 JAXB

java - 使用 validator 针对 xsd 验证soap xml

javascript - 正则表达式检查具有一系列模式的数字

asp.net-mvc-3 - MVC 3复杂的模型验证

xml - 在 XML XSD 中定义递归代数数据类型