Catching CppWebBrowser XML answer in C++ builder

Hi,

I trying to catch XML answer from CppWebBrowser. I find some solutions working for html, but have no idea how to make it for xml.
Leo01010101Asked:
Who is Participating?
 
George TokasCommented:
What version of C++ Builder you are using?
Looks like 2006+
No problem there anyway...
You can process buff or the c_str part that is a pointer to char....
Try using a temp string adding from buff till new line as follows as example:
AnsiString S = "";
for(int j = 1; j < Source.Length(); j++)
{
   if(S[ j ] == "new line code")//sorry I am at home and can't check the exact...
   {
     Memo1->Lines->Add(S);
     S = "";
   }
   else
   {
     S += Source[ j ];
   }
}

I believe this way will work....

George Tokas.
0
 
George TokasCommented:
Get access to the "Document" property of CppWebBrowser. The contents will be the html response. There has to be included the xml part you want.
Isolate the xml part and process it...

George Tokas.
0
 
Leo01010101Author Commented:
I'm trying to catch answer from OSM Nominatim,
sending inquiry like this :

"http://nominatim.openstreetmap.org/reverse?format=xml&lat=53.554671&lon=19.587120&zoom=18&addressdetails=1"

by using Navigate of CppWebBrowser.

My procedure looks like :

void __fastcall TMapShowForm::CppWebBrowser1DocumentComplete(
      TObject *Sender, LPDISPATCH pDisp, Variant *URL)
{
   static int ct=0;
   char buff[100000];
   AnsiString Source;
   ct++; if(ct>1) return;
   CppWebBrowser1->Stop();
   IHTMLDocument2 *htm = NULL;
   IXMLDocument2 *xml = NULL;

    if( CppWebBrowser1->Document )
    {
     if( SUCCEEDED(CppWebBrowser1->Document->QueryInterface(IID_IHTMLDocument2,(LPVOID*)&htm)) )
     {
       CppWebBrowser1->Document->QueryInterface(IID_IXMLDocument2,(LPVOID*)&xml);
        IPersistStreamInit *spPsi = NULL;
        if(SUCCEEDED(htm->QueryInterface(IID_IPersistStreamInit, (LPVOID*)&spPsi)) && spPsi)
        {
            IStream *spStream = NULL;
            OleCheck(CreateStreamOnHGlobal(NULL, true, &spStream));
            if(spStream)
            {
                __int64 nSize = 0;
                STATSTG ss;
                LARGE_INTEGER nMove;
                nMove.QuadPart = 0;
                OleCheck(spPsi->Save(spStream, true));
                OleCheck(spStream->Seek(nMove, STREAM_SEEK_SET, ULARGE_INTEGER*)&nSize));
                OleCheck(spStream->Stat(&ss, STATFLAG_NONAME));
                nSize = ss.cbSize.QuadPart;
                Source.SetLength(nSize);
                OleCheck(spStream->Read((void *)Source.data(), nSize, (ULONG*)&nSize));
                OleCheck(spStream->Release());
            }
            spPsi->Release();
        }
        htm->Release();
     }
    }
   strcpy(buff,Source.c_str());
}

Open in new window


I have no idea how to take out XML.
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
George TokasCommented:
Source and buff have the content of HTML in ANSI (probably) format...
Source may misguide you because if you check with the IDE check will stop in the first zero temination...
Try adding a TMemo and use:
Memo1->Lines->Add(Source);
There you will examine the contents and see where the XML part is.
Test that first and we will see..
I think you will find your way after that...
If not I would be here (as allways)...

George Tokas.
0
 
Leo01010101Author Commented:
I tried as proposed  :  

Memo1->Lines->Add(Source);  

In Memo was displayed only 2 characters.
0
 
George TokasCommented:
After this line?
strcpy(buff,Source.c_str());
Looks strange...
Check Source->Length() what is the size?
Must have the size of the HTML reply (the content of the page)...

George.
0
 
Leo01010101Author Commented:
Yes, I placed it after. Length of Source is 15048.
The length is too big I afraid becouse answer looks in this way :  

 <?xml version="1.0" encoding="UTF-8" ?>
- <reversegeocode timestamp="Wed, 12 Sep 12 19:12:04 +0100" attribution="Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright" querystring="format=xml&lat=54.354671&lon=18.587120&zoom=18&addressdetails=1">
  <result place_id="95249780" osm_type="way" osm_id="105780202" lat="54.3545101013044" lon="18.5871780910688">24, Belgradzka, Emaus, Piecki-Migowo, Gdansk, pomorskie, 80-286, Polska</result>
- <addressparts>
  <house_number>24</house_number>
  <road>Belgradzka</road>
  <place>Emaus</place>
  <suburb>Piecki-Migowo</suburb>
  <city>Gdansk</city>
  <county>Gdansk</county>
  <state>pomorskie</state>
  <postcode>80-286</postcode>
  <country>Polska</country>
  <country_code>pl</country_code>
  </addressparts>
  </reversegeocode>


Anwer displayed in Memo1 :   ¿t<      (3 signs)
0
 
Leo01010101Author Commented:
I'm using BC++ 6.0.  Yes, this works and really it was 15048 signs of HTML code.  To take XML data it could be not a simplest way. Is it possible to use IXMLDocument to catch XML data from CppWebBrowser in simpler way?
0
 
George TokasCommented:
BCB6 and problem with AnsiString?
Looks strange... I had similar problems with versions newer... 6 is my main IDE...
I think there is a way to use XMLDocument but didn't tried though...
I would prefer to isolate the XML part from inside TMemo->Lines and make my own parser in a class....
Starting is allways "<?xml..." in starting of the line and "..xml>" is the closing of the content...
What you have inside TMemo is of String* type or - lets say kid of - TStringList.
Create a new one and add the lines containing the XML part...
Then process it as you like...
As I said didn't like the XMLDocument component... Early versions had bugs...

George Tokas.
0
 
Leo01010101Author Commented:
Thank you for advice, I will follow this way.
0
 
George TokasCommented:
You are welcome...
I will be here if you need anything else.

George Tokas.
0
 
Leo01010101Author Commented:
Thank you once more, I see that you also using BCB6. I have some projects under this IDE and I was thinking to migrate to Embarcadero RAD XE2 ( I have it but never used ). I tryed to migrate but find problems with AnsiStrings. Have you any experiences in migrating from BCB6 to lastet versions?
0
 
George TokasCommented:
Yes...
Change AnsiString to UnicodeString...
Solves 99% of problems there....
By the way XE3 hit the market and looks promising...

George Tokas.
0
 
Leo01010101Author Commented:
Thanks, it was nice to hear the Expert, hope you will find time when I come with new ask about BCB.
0
 
George TokasCommented:
>>hear the Expert
Still learning as anyone else here....
>>hope you will find time when I come with new ask about BCB.
Allways be here trying to help.

George.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.