如何使用 apache camel 验证 xsd? [英] How can I validate xsd using apache camel?
问题描述
我正在使用 apacheservicemix 并尝试使用 apache camel 验证 xml 文档.我有一条名为 Students_route.xml 的路线:
I'm using apacheservicemix and I try to validate a xml document with apache camel. I have this route called 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 文件是否有效的目录.
I created 3 directories called: valid, invalid and finally. After I run in karaf "start students_route.xml" nothing happens. When I look into logs I get no errors just some messages like this: "Route: route2 started and consuming from: Endpoint[file://project/students.xml]".I imagine that a file should be created under valid/invalid directories whether the xml file is valid or not.
我是这项技术的新手,我不知道如何使这项工作发挥作用.我将衷心感谢您的帮助.提前致谢!
I'm new to this technologies and I have no idea how to make this work. I would really appreciate your help. Thank you in advance!
推荐答案
这是一个工作示例:
<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>
玩得开心!
这篇关于如何使用 apache camel 验证 xsd?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!