2016-02-15 25 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 }