1

次のXQueryコードを実行しようとしています-

declare variable $doc="E:\Arvind\Workspace\XML\test.xml"
let $page_title:= $doc//title[contains(.,'Error 404')]
let $assignee_block := $doc//div[@class="patent_bibdata" and contains(.,'Original        Assignee')]
for $assignee_link in $assignee_block/a 
for $assignee_link_url in $assignee_link/@href
where  contains($assignee_link_url,'inassignee') 
 return
if($page_title) then
     '404'
 else if ($assignee_block) then 
        return data($assignee_link)
  else return 'Missing' 

しかし、私はこのエラーが発生しています-

 XQuery syntax error in #...) else return 'Missing'#:
 Unexpected token "<eof>" in path expression

私はここで何が間違っているのですか?静的テキスト「Missing」を最後のelseに表示するにはどうすればよいですか?

4

2 に答える 2

0

式内では、キーワードifを指定する必要はありません。return次に、変数宣言には次:=の代わりにが必要です=

declare variable $doc := "E:\Arvind\Workspace\XML\test.xml";
let $page_title := $doc//title[contains(.,'Error 404')]
let $assignee_block := $doc//div[@class="patent_bibdata" and contains(.,'Original        Assignee')]
for $assignee_link in $assignee_block/a 
for $assignee_link_url in $assignee_link/@href
where contains($assignee_link_url,'inassignee') 
return
  if($page_title) then '404'
  else if ($assignee_block) then data($assignee_link)
  else 'Missing' 

開発中は、構文エラーのフィードバックを直接提供するBaseXGUIやoXygenなどのエディターを使用すると役立つ場合があります。

于 2012-09-01T20:24:03.580 に答える
0

私はここで何が間違っているのですか?

非常に明白です:

$doc文字列として宣言されます="E:\Arvind\Workspace\XML\test.xml"

次の行:

let $page_title:= $doc//title[contains(.,'Error 404')] 

XPath疑似演算子//を文字列に適用することはできません。

この問題を修正するには、以下を変更します。

declare variable $doc="E:\Arvind\Workspace\XML\test.xml"

declare variable $doc=doc("E:\Arvind\Workspace\XML\test.xml")

また、URIdoc()を受け入れるため、ファイルパスは次のように提示する必要があります。

declare variable $doc=doc("file:///E:/Arvind/Workspace/XML/test.xml")
于 2012-09-01T23:28:41.730 に答える