1

I am across a problem while parsing xml document. Actually I am using XMl Binding wizard to extract the attributes values but every time it throws exceptions.

Here is my 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>

My Code :

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;

Every time I get error : An opening '[' character was expected Line:23

Any fragment of code or suitable links will be appreciated.

EDIT: Thanks, But my limited knowledge in Delphi couldn't catch the posted instructions.By the way, This xml binding seems to be valid in C++ Builder 6. Using xml binding, I am able to extract the required fields like downloadurl, mediaurl, file, etc. from the same xml. Here is the code in 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;

I don't know why the same logic doesn't work in delphi xe4. By the way the xml is valid since it opens normally in Internet explporer and Chrome. If you have any other methods to parse this xml then please do post reply.

Rabi Jayasawal
  • 421
  • 9
  • 16
  • 1
    I'm going to go out on a limb here, using my psychic debugging skills, and say that you probably have something wrong in your `GetConversionCloud` function. However, I also can state absolutely that I can't tell you what that problem is, because you didn't post the code for the `GetCoversionCloud` function in your question. – Ken White Mar 30 '14 at 06:05
  • My guess would be that this is not the real XML being parsed, and that the real XML really does have an error in it, otherwise the parser would not be complaining. It is complaining about the `CDATA` of `downloadurl`, so either the `CDATA` of `mediaurl` has an illegal character that breaks the XML, or there is a nonprintable character present in `downloadurl` that does not belong. – Remy Lebeau Mar 30 '14 at 16:21
  • Question edited and improved. Please have a look. – Rabi Jayasawal Mar 31 '14 at 10:26

0 Answers0