2009-11-22 65 views
0

這裏是XQuery的輸出,我得到的一個例子:的XQuery:怪異XSI屬性插入我的XQuery的輸出

<clinic> 
    <Name xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Healthy Kids Pediatrics</Name> 
    <Address xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">510 W 27th St, Los Angeles, CA 90007</Address> 
    <PhoneNumberList>213-555-5845</PhoneNumberList> 
    <NumberOfPatientGroups>2</NumberOfPatientGroups> 
</clinic> 

正如你所看到的,在<Name><Address>標籤,有這些奇怪的xmlns :被添加到它的xsi標籤。

有趣的是,如果我去我的XML文件的頂部,並刪除:

<?xml version="1.0" encoding="UTF-8"?> 
<?xml-stylesheet type="text/xsl" href="vaccination.xsl"?> 
<Vaccination xsi:noNamespaceSchemaLocation="vaccination.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 

短語

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 

然後現在我的XQuery XML輸出看起來像這樣(這是我想要的)

<clinic> 
    <Name>Healthy Kids Pediatrics</Name> 
    <Address>510 W 27th St, Los Angeles, CA 90007</Address> 
    <PhoneNumberList>213-555-5845</PhoneNumberList> 
    <NumberOfPatientGroups>2</NumberOfPatientGroups> 
</clinic> 

但是,當我在瀏覽器中查看我的XML,它會給出一個錯誤,並且顯示事端摹狀:

XML Parsing Error: prefix not bound to a namespace 
Location: file:///C:/Users/Pac/Desktop/csci585-hw3/vaccination.xml 
Line Number 3, Column 1:<Vaccination xsi:noNamespaceSchemaLocation="vaccination.xsd"> 
^ 

有誰有如何刪除我的XQuery輸出那些XSI標籤沒有打破我的XML/XSL的想法?

回答

2

從頂層節點刪除名稱空間聲明使得XML文檔無效,因爲使用了xsi前綴但未聲明。當您嘗試在查詢中加載文檔時,這應該導致錯誤。

我假設名稱和地址節點直接從源文檔複製,並構建其他節點。

從源文檔複製節點時,源節點中的範圍名稱空間與包含該副本的節點中的範圍名稱空間組合在一起。這些組合的方式由copy-namespaces-mode指定。

在你的情況下,你希望命名空間是從父節點(查詢中的節點)繼承的,但你不想保留源文檔中不需要的命名空間。

這可以通過將下面的行到查詢的頂部來實現:

declare copy-namespaces no-preserve, inherit; 
+0

完善。奇蹟般有效。謝謝! – sivabudh 2009-11-23 23:07:43