将结果存储到记录中的麻烦

发布于 2024-07-16 04:20:44 字数 1087 浏览 4 评论 0原文

我正在解析 XML 文件并将结果存储在记录中,但遇到了一些问题。

我试图将结果(我的 XML 标签的内容)存储到我的记录的字段中。

我的记录(目前只有 1 组 XML 元素)。 我认为 Parser.curconten 导致了问题...

    Type

TXMLAlert=Record
alert, desc, action:string;
end;

Var
MyXMLAlert:TXMLAlert;

MyXMLAlert.alert:=Parser.CurContent
MyXMLAlert.desc:=Parser.CurContent
MyXMLAlert.action:=Parser.CurContent

以下是我的解析器代码;

procedure ProcessXML();
var
  Parser : TXmlParser;
  rule, alert: string;
  i:integer;
  memo1:Tmemo;


begin
  Parser := TXmlParser.Create;
  Parser.Normalize := TRUE;
  Parser.LoadFromFile ('c:\parser.xml');
  Parser.StartScan;

  while Parser.Scan do
    case Parser.CurPartType of
     ptStartTag,
    ptEmptyTag : Form1.Memo1.Lines.Add ('New Element: ' + Parser.CurName);
    ptContent  : Form1.Memo1.Lines.Add ('Content of Element ' +
    Parser.Curname + ':' + Parser.CurContent);
      end;
  Parser.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
  ProcessXML();
end;

end.

程序解析器正常,标签的内容显示在 memo1 中... 为什么记录没有获取内容结果有什么想法吗? 谢谢,拉泽斯佩佩

I am parsing an XML file and storing the results in a record, but am having some trouble.

Im trying to store the results (content of my XML tags) into the fields of my record..

My record (at the moment there is only 1 set of XML elements). I think that the Parser.curconten is causing the problem...

    Type

TXMLAlert=Record
alert, desc, action:string;
end;

Var
MyXMLAlert:TXMLAlert;

MyXMLAlert.alert:=Parser.CurContent
MyXMLAlert.desc:=Parser.CurContent
MyXMLAlert.action:=Parser.CurContent

The following is my parser code;

procedure ProcessXML();
var
  Parser : TXmlParser;
  rule, alert: string;
  i:integer;
  memo1:Tmemo;


begin
  Parser := TXmlParser.Create;
  Parser.Normalize := TRUE;
  Parser.LoadFromFile ('c:\parser.xml');
  Parser.StartScan;

  while Parser.Scan do
    case Parser.CurPartType of
     ptStartTag,
    ptEmptyTag : Form1.Memo1.Lines.Add ('New Element: ' + Parser.CurName);
    ptContent  : Form1.Memo1.Lines.Add ('Content of Element ' +
    Parser.Curname + ':' + Parser.CurContent);
      end;
  Parser.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
  ProcessXML();
end;

end.

Program parser fine and the content of tags is displayed in memo1...
Any ideas why the record is not picking up the results of content?
Thanks, Lazerspewpew

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我的鱼塘能养鲲 2024-07-23 04:20:44

看起来您并没有在记录代码中每次调用 CurContent 之间调用 Scan,因此您实际上不会继续输入。 它看起来也不像您的记录代码像备忘录代码那样跳过开始和结束标签。 就此而言,我无法确定您在记录代码中执行的设置与您在备忘录代码中执行的设置相同。 在记录代码运行时,Parser 是否引用已从文件加载数据的有效 TXmlParser 实例? 已经开始扫描了吗?

随意的缩进和几个未使用的变量使我们很难确信我们确实看到了导致您描述的问题的代码。

备忘录控件得到什么? (复制并粘贴。)记录得到的是什么而不是你所期望的?

It doesn't look like you're calling Scan between each call to CurContent in your record code, so you won't actually advance through the input. It also doesn't look like your record code is skipping over start and end tags the way you memo code is. For that matter, I can't be sure you're doing any of the same setup in your record code as you are in your memo code. At the point where your record code runs, does Parser refer to a valid TXmlParser instance that has loaded data from a file yet? Has it started scanning yet?

The haphazard indentation and the several unused variables makes it hard to be confident we're really seeing code that causes the problem you describe anyway.

What does the memo control get? (Copy and paste.) And what does the record get instead of what you expected?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文