2016-02-15 57 views
0

我正在使用Delphi7 OmniXML。如何使用OmniXML在XML中搜索字符串值內的斜槓符號

在我的xml我有一個包含 '/'

XML字段:

... 
<R2>002-000004/13</R2> 
... 

當我搜索包含登錄XML值 '/' 我OmniXml返回錯誤。

iNodeKupac := FXMLDocument.SelectSingleNode(
      '//[R2=''' + '002-000004/13' + ''']' 
     ); 

如何對此字段進行預搜索搜索?

回答

0

在OmniXMLPath單元中更改PosEX,現在它可以工作。

function TXMLXPathEvaluator.PosEx(ch: WideChar; const s: XmlString; offset: integer = 1): integer; 
var 
    quoteCount, startIndex, stopIndex: integer; 
    startText, stopText : String; 
begin 
    quoteCount := 0; 
    startText := ''; startIndex := 0; 
    stopText := ''; stopIndex := 0; 
    for Result := offset to Length(s) do begin 
    if (s[Result] = '=') and (startText = '') then begin 
     startText := '='; 
     startIndex := Result; 
     end 
    else if (s[Result] = '''') and (startText = '=') and ((startIndex+1) = Result) then begin 
     startText := '='''; 
     startIndex := -1; 
     end 
    else begin 
     startText := ''; 
     startIndex := 0; 
    end; 

    if (s[Result] = '''') and (stopText = '') then begin 
     stopText := ''''; 
     stopIndex := Result; 
     end 
    else if (s[Result] = ']') and (stopText = '''') and ((stopIndex+1) = Result) then begin 
     stopText := ''']'; 
     stopIndex := -1; 
     end 
    else begin 
     stopText := ''; 
     stopIndex := 0; 
    end; 

    if startIndex = -1 then Inc(quoteCount); 
    if stopIndex = -1 then Dec(quoteCount); 

    if (s[Result] = ch) and (quoteCount = 0) then 
     Exit; 
    end; 
    Result := 0; 
end; { TXMLXPathEvaluator.PosEx }