1

解析 xml 文档时遇到问题。实际上我正在使用 XMl 绑定向导来提取属性值,但每次它都会引发异常。

这是我的xml:

<?xml version="1.0" encoding="UTF-8"?>
<conversioncloud version="1.2">
    <status step="finished"/>
    <id>
        <![CDATA[T9Nr96Hy]]>
    </id>
    <videoid>
        <![CDATA[92590917]]>
    </videoid>
    <server>
        <![CDATA[server12]]>
    </server>
    <file>
        <![CDATA[my file ofr xmfhf.ext]]>
    </file>
    <service>
        <![CDATA[myservice]]>
    </service>
    <mediaurl>
        <![CDATA[web address here]]>
    </mediaurl>
    <downloadurl>
        <![CDATA[download url here]]>
    </downloadurl>
    <downloadserver>
        <![CDATA[srv55]]>
    </downloadserver>
    <downloadhash>
        <![CDATA[upyxqnJmsKuwbGttn5OcaXCs26SqaG60l5acbmpmm2pka7WEz9bXnaeE14ujqK2tyMg%3D]]>
    </downloadhash>
    <filesize>
        <![CDATA[2.77 MB]]>
    </filesize>
    <debuginfo>
        <![CDATA[T9Nr96Hy|92590917|srv55|1396163808|ListenToYoutube]]>
    </debuginfo>
</conversioncloud>

我的代码:

procedure TForm1.Button10Click(Sender: TObject);
var
  Cloud : IXMLConversioncloudType;
  size : Integer;
begin
  XMLDocument1.XML.Text := Memo1.Text;
  Cloud := Getconversioncloud(XMLDocument1);

// trying to display "file" field from xml document above  
ShowMessage(Cloud.File_);
end;

每次我得到错误:一个开头的'['字符应该是行:23

任何代码片段或合适的链接将不胜感激。

编辑:谢谢,但是我在 Delphi 中的有限知识无法捕捉到发布的说明。顺便说一下,这个 xml 绑定似乎在 C++ Builder 6 中有效。使用 xml 绑定,我能够提取所需的字段,如 downloadurl、mediaurl , 文件等来自同一个 xml。这是 C++ Builder 6 中的代码。

void __fastcall YoutubeMax::ShowFileInfo(String aResponse)
{
        frmMain->XMLDocument1->XML->Text =  aResponse;
        _di_IXMLconversioncloudType cloud = Getconversioncloud(frmMain->XMLDocument1);

        // find index of files
        int url = cloud->ChildNodes->IndexOf("downloadurl");
        int title =  cloud->ChildNodes->IndexOf("file");
        int size = cloud->ChildNodes->IndexOf("filesize");

        // Fill the details
        frmMain->lblYoutubeFilename->Caption = "Title : " + cloud->ChildNodes->Nodes[title]->ChildNodes->Nodes[0]->Text;
        frmMain->lblYoutubeFileSize->Caption = "File Size : " + cloud->ChildNodes->Nodes[size]->ChildNodes->Nodes[0]->Text;
        frmMain->memoYoutubeMp3Link->Text = cloud->ChildNodes->Nodes[url]->ChildNodes->Nodes[0]->Text;

我不知道为什么相同的逻辑在 delphi xe4 中不起作用。顺便说一句,xml 是有效的,因为它在 Internet explporer 和 Chrome 中正常打开。如果您有任何其他方法来解析此 xml,请回复。

4

0 回答 0