2010-01-07 39 views
0

我正在使用Apache Xerces 3.0.1 XInclude。我想使用xinclude機制來包含XML文件。我有三個XML文件都在同一個目錄中。 test_a.xml x包含test_b.xml,其中包含test_c.xml。當我只有test_a.xml xinclude test_b.xml時,它可以工作。但是,當我有test_b.xml xinclude test_c.xml時,出現以下命令行錯誤:xerces xinclude錯誤

C:\ digital_receiver \ test> XInclude.exe test_a.xml test_z.xml 正在解析test_a.xml ... 致命錯誤文件C:\ digital_receiver \ test/test_a.xml,第3行,字符34 消息:在完成的URI 中找不到任何方案。

test_a.xml:

<?xml version="1.0" encoding="ISO-8859-1"?> 
<test_a xmlns:xi="http://www.w3.org/2001/XInclude"> 
    <xi:include href="test_b.xml"/> 
</test_a> 

test_b.xml:

<?xml version="1.0" encoding="ISO-8859-1"?> 
<test_b xmlns:xi="http://www.w3.org/2001/XInclude"> 
    <ch>5</ch> 
    <xi:include href="test_c.xml"/> 
</test_b> 

test_c:XML:

<?xml version="1.0" encoding="ISO-8859-1"?> 
<test_c> 
    <channel>1</channel> 
</test_c> 

任何幫助,將不勝感激。

回答

0

據我所知,你的XML是好的,但我不會說這是最後一個字。

這是我的猜想您在Xerces的XInclude處理中遇到了一個錯誤。我注意到雖然這段代碼差不多三年了,但它顯然不是released until Xerces 3.0,所以它可能相對未經測試。 (並且考慮到在XInclude中處理base URIs of included documents的方式,這裏出現bug的可能性看起來好像大於0.)

作爲一種解決方法,我建議您按照錯誤消息的建議進行操作:將方案添加到包含文件的URI。不幸的是,對於文件URI,這也意味着你需要使用絕對URI。

test_a.xml:

<?xml version="1.0" encoding="ISO-8859-1"?> 
<test_a xmlns:xi="http://www.w3.org/2001/XInclude"> 
    <xi:include href="file://path/to/directory/test_b.xml"/> 
</test_a> 

test_b.xml:

<?xml version="1.0" encoding="ISO-8859-1"?> 
<test_b xmlns:xi="http://www.w3.org/2001/XInclude"> 
    <ch>5</ch> 
    <xi:include href="file://path/to/directory/test_c.xml"/> 
</test_b> 

UPDATE:確實是有a similar bug在apache.org。 (我認爲它描述了相同的問題,但報告中的措詞使得聽起來像甚至是一個單個包含層將在使用相對路徑時失敗。)

+0

感謝Dan。我能夠獲得單層包容以正常工作。我想我可以等到他們修復這個錯誤。 – sizzle 2010-01-11 17:04:46