我有一組XQuery轉換,我在存儲在Sedna數據庫中的文件上運行。他們大致有以下格式:XQuery註釋中的奇數行爲
declare namespace ns0 = "http://www.someuri.com/foo.xsd";
declare namespace ns1 = "http://www.someuri.com/bar.xsd";
(:Declare a few functions like the following:)
declare function local:to-xs-boolean(
$string as xs:string?
)
as xs:boolean? {
if (fn:upper-case($string) = 'Y') then
xs:boolean('true')
else
if (fn:upper-case($string) = 'N') then
xs:boolean('false')
(:if it isn't Y or N then attempt a normal cast - this will fail if it
it isn't any of 'true', 'false', 1, or 0 :)
else
if ($string != '') then
xs:boolean($string)
else
()
(:endif:)
(:endif:)
};
(:Omitted several other functions:)
(:Start the main program:)
(: { :)
for $formName in /ns0:formName
return
<ns1:newFormName>
{
let $address := $formName/ns0:Address
return
<NewAddress>{
(:Omitted code and elements unrelated to this question:)
}</NewAddress>
}
(:Omitted code and elements unrelated to this question:)
</ns1:newFormName>
現在這是我的問題。你在'for'上方看到'(:{:)'的那一行?它應該是一個評論,但由於某種原因,對於我的查詢的正確功能至關重要。如果我完全刪除(或刪除「{」從裏面的評論)我得到
SEDNA Message: ERROR XPDY0002
It is a dynamic error if evaluation of an expression relies on some part of the dynamic context that has not been assigned a value.
如果我取消它(太行剛讀「{」)我得到
SEDNA Message: ERROR XPST0003
It is a static error if an expression is not a valid instance of the grammar defined in A.1 EBNF.
Details: at (393:1), syntax error, unexpected {
at (798:33), syntax error, unexpected end of file, expecting "," or }
如果我有兩個註釋掉,並添加相應的「}」到文件的末尾,我得到
SEDNA Message: ERROR XPST0003
It is a static error if an expression is not a valid instance of the grammar defined in A.1 EBNF.
Details: at (393:1), syntax error, unexpected {
如果我添加其他文本到評論(如「(:文本FOO酒吧巴茲(){嗒嗒:) '),只要我在那裏留下那個'{',它就會繼續工作。
有沒有人見過這個或有任何想法可能會導致它?這不是一個關鍵問題(我可以確保在所有轉換中都有'(:{:)'),但它確實讓我好奇。所以謝謝你的幫助,甚至只是讓我迷惑。
哦,另外一個快速的注意 - 我不知道這有什麼差別,但是我用的查爾斯·福斯特的塞德娜API運行查詢出來的Java(http://www.cfoster.net/sedna/)
編輯:這是一個不同的查詢,我只是寫這說明了同樣的問題。這似乎對我來說是可重現的,但如果它是語法錯誤相關,它可能只是我重現語法錯誤。我也會離開老的,所以這個問題的未來觀衆不會感到困惑。
declare namespace ns0 = "http://www.someuri.com/InitialSchema.xsd";
declare namespace ns1 = "http://www.someuri.com/FinalSchema.xsd";
declare function local:to-address(
$recipient as xs:string?,
$line1 as xs:string?,
$line2 as xs:string?,
$line3 as xs:string?,
$city as xs:string?,
$provinceOrState as xs:string?,
$country as xs:string?,
$postalOrZIP as xs:string?
)
as element() {
if (fn:upper-case($country) = 'CA' or fn:upper-case($country) = 'US') then
if (fn:upper-case($country) = 'CA') then
<CanadianAddress>
<City>{ $city }</City>
<Country>{ $country }</Country>
<PostalCode>{ $postalOrZIP }</PostalCode>
<Province>{ $provinceOrState }</Province>
<Recipient>{ fn:normalize-space($recipient) }</Recipient>
<StreetAddress>{ $line1 }</StreetAddress>
<StreetAddress>{ $line2 }</StreetAddress>
<StreetAddress>{ $line3 }</StreetAddress>
<StreetAddress/>
</CanadianAddress>
else
<USAddress>
<City>{ $city }</City>
<Country>{ $country }</Country>
<ZipCode>{ $postalOrZIP }</ZipCode>
<State>{ $provinceOrState }</State>
<Recipient>{ fn:normalize-space($recipient) }</Recipient>
<StreetAddress>{ $line1 }</StreetAddress>
<StreetAddress>{ $line2 }</StreetAddress>
<StreetAddress>{ $line3 }</StreetAddress>
</USAddress>
(:endif:)
else
if ($country != '') then
<InternationalAddress>
<City>{ $city }</City>
<Country>{ $country }</Country>
<PostalCode>{ $postalOrZIP }</PostalCode>
<Recipient>{ fn:normalize-space($recipient) }</Recipient>
<StreetAddress>{ $line1 }</StreetAddress>
<StreetAddress>{ $line2 }</StreetAddress>
<StreetAddress>{ $line3 }</StreetAddress>
</InternationalAddress>
else
<CanadianAddress>
<City>{ $city }</City>
<Country>{ $country }</Country>
<PostalCode>{ $postalOrZIP }</PostalCode>
<Province>{ $provinceOrState }</Province>
<Recipient>{ fn:normalize-space($recipient) }</Recipient>
<StreetAddress>{ $line1 }</StreetAddress>
<StreetAddress>{ $line2 }</StreetAddress>
<StreetAddress>{ $line3 }</StreetAddress>
<StreetAddress/>
</CanadianAddress>
(:endif:)
(:endif:)
};
(:{:)
for $addressForm1 in /ns0:AddressForm
let $token := xs:integer(data($addressForm1/ns0:submissionID))
return
<ns1:NewAddressForm>
<SubmissionID>{ data($addressForm1/ns0:submissionID) }</SubmissionID>
{
let $currentAddress := $addressForm1/ns0:currentAddress
return
<NewAddress>{
local:to-address(
concat(
$addressForm1/ns0:fullName/ns0:firstName,
' ',
substring(data($addressForm1/ns0:fullName/ns0:middleName), 1, 1),
' ',
$addressForm1/ns0:fullName/ns0:lastName
),
data($currentAddress/ns0:line1),
data($currentAddress/ns0:line2),
data($currentAddress/ns0:line3),
data($currentAddress/ns0:city),
data($currentAddress/ns0:provinceOrState),
data($currentAddress/ns0:country),
data($currentAddress/ns0:postalOrZipCode)
)
}</NewAddress>
}
</ns1:NewAddressForm>
這裏是新的查詢
<?xml version="1.0"?>
<ns0:AddressForm xmlns:ns0="http://www.someuri.com/InitialSchema.xsd">
<ns0:submissionID>23774</ns0:submissionID>
<ns0:fullName>
<ns0:firstName>First</ns0:firstName>
<ns0:middleName>Middle</ns0:middleName>
<ns0:lastName>Last</ns0:lastName>
</ns0:fullName>
<ns0:currentAddress>
<ns0:line1>Line 1</ns0:line1>
<ns0:line2>Line 2</ns0:line2>
<ns0:line3>Line 3</ns0:line3>
<ns0:city>City</ns0:city>
<ns0:provinceOrState>Province</ns0:provinceOrState>
<ns0:postalOrZipCode>H0H 0H0</ns0:postalOrZipCode>
<ns0:country>CA</ns0:country>
</ns0:currentAddress>
</ns0:AddressForm>
一些樣本數據。如果它是一個語法錯誤,這是背後有人會這麼好心地指出來我這行是上?
它是一個非常有效的XQuery語法。看起來像你的Java層XQueryService xQuery Parser有一些問題? – kadalamittai 2011-02-18 03:34:49
@ kadalamittai是的,這可能是這裏發生的事情。但我仍然覺得很奇怪。我可以理解解析器在評論中存在不匹配的'{',但是當沒有一個對我來說很奇怪時遇到麻煩。 – Jason 2011-02-18 14:07:36