2012-02-03 84 views
2

我正在寻求使用JAXB解析来自调用Sharepoint 2010的REST服务的Atom提要,并让JAXB绑定和编译发生在eclipse中。我下载了几个不同版本的我在网上找到的atom xsd(它们仅在一些头文件属性中有所不同),包括这一个(http://www.kbcafe.com/rss/atom.xsd.xml),但是CONSISTENTLY获得了其中下面的错误,无论我用:JAXB解析Atom.xsd产生验证错误

 [xjc] [WARNING] schema_reference.4: Failed to read schema document 'http://www.w3.org/2001/03/xml.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>. 
    [xjc] line 14 of file:/C:/rest_workspace/eDocs/src/gov/afms/edocs/rest/jaxb/schemas/AtomSchema2.xsd 
    [xjc] [ERROR] src-resolve: Cannot resolve the name 'xml:base' to a(n) 'attribute declaration' component. 
    [xjc] line 292 of file:/C:/rest_workspace/eDocs/src/gov/afms/edocs/rest/jaxb/schemas/AtomSchema2.xsd 
    [xjc] [ERROR] s4s-elt-must-match.1: The content of 'commonAttributes' must match (annotation?, ((attribute | attributeGroup)*, anyAttribute?)). A problem was found starting at: attribute. 
    [xjc] line 292 of file:/C:/rest_workspace/eDocs/src/gov/afms/edocs/rest/jaxb/schemas/AtomSchema2.xsd 

我看到一些评论说taht Java5中的Xerces有一些问题,但我赞同脱离我的Ant脚本我的Java版本,并且正在使用1.6。在第14行的节点是:

<xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/03/xml.xsd" /> 

节点在第292行是:

 <xs:attribute ref="xml:base" /> 

注意,Eclipse也是萎靡不振这些东西为错误。对于警告,eclipse表示“XSD:The location'http://www.w3.org/2001/03/xml.xsd'尚未解决”,对于错误行,它表示“XSD:Attribute reference'http: //www.w3.org/XML/1998/namespace#base'未解决“。它也出现在293上,与上面类似,但指向lang而不是base。

对我来说,解析器试图解析对名称空间文档的引用是很奇怪的,因为这似乎只是一个解释名称空间的HTML文档,而不是XSD或DTD。但是这个Atomschema2.xsd不是我编造的,而是下载的。

我应该在这里做什么?有更好的原子模式吗?我应该修改我下载的模式以修改引用吗?第三件事?

+0

您可能会发现以下文章很有用:http://blog.bdoughan.com/2010/09/processing-atom-feeds-with-jaxb.html – 2012-02-03 15:38:09

回答

2

该错误通常是由xml.xsd文件顶部的DTD DOCTYPE引起的;我从来没有试图用JAXB解决它,但我可以保证,如果你下载,修复引用,并从xml.xsd文件中删除<!DOCTYPE ... []>,那么JAXB可以开箱即用您指向的模式(我刚刚在NetBeans 7.1中尝试过,没有任何问题)。我想现在一个好问题是如何让JAXB的xjc忽略DTD ...

更新:在命令行中的catalog可能会这样做,请阅读this