2012-02-03 85 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