首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当字符串值中有斜杠符号时,如何使用OmniXML搜索XML

当字符串值中有斜杠符号时,如何使用OmniXML搜索XML
EN

Stack Overflow用户
提问于 2016-02-15 14:02:22
回答 1查看 46关注 0票数 0

我用的是Delphi7,OmniXML。

在我的xml中,我有一个包含'/‘的字段

XML:

代码语言:javascript
复制
...
<R2>002-000004/13</R2>
...

当我在XML中搜索包含符号'/‘的值时,我的OmniXml返回错误。

代码语言:javascript
复制
iNodeKupac := FXMLDocument.SelectSingleNode(
          '//[R2=''' + '002-000004/13' + ''']'
          );

如何在这片土地上预编searh?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-15 15:32:57

改变了PosEX在OmniXMLPath单元,现在它的工作。

代码语言:javascript
复制
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 }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35411381

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档