?
Solved

Catching CppWebBrowser XML answer in  C++ builder

Posted on 2012-09-11
15
Medium Priority
?
1,104 Views
Last Modified: 2012-09-13
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.
0
Comment
Question by:Leo01010101
  • 8
  • 7
15 Comments
 
LVL 16

Expert Comment

by:George Tokas
ID: 38390057
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
 

Author Comment

by:Leo01010101
ID: 38391448
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
 
LVL 16

Expert Comment

by:George Tokas
ID: 38391846
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:Leo01010101
ID: 38392032
I tried as proposed  :  

Memo1->Lines->Add(Source);  

In Memo was displayed only 2 characters.
0
 
LVL 16

Expert Comment

by:George Tokas
ID: 38392059
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
 

Author Comment

by:Leo01010101
ID: 38392131
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
 
LVL 16

Accepted Solution

by:
George Tokas earned 2000 total points
ID: 38392490
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
 

Author Comment

by:Leo01010101
ID: 38393844
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
 
LVL 16

Expert Comment

by:George Tokas
ID: 38393867
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
 

Author Comment

by:Leo01010101
ID: 38393944
Thank you for advice, I will follow this way.
0
 
LVL 16

Expert Comment

by:George Tokas
ID: 38393955
You are welcome...
I will be here if you need anything else.

George Tokas.
0
 

Author Comment

by:Leo01010101
ID: 38394196
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
 
LVL 16

Expert Comment

by:George Tokas
ID: 38394250
Yes...
Change AnsiString to UnicodeString...
Solves 99% of problems there....
By the way XE3 hit the market and looks promising...

George Tokas.
0
 

Author Comment

by:Leo01010101
ID: 38394318
Thanks, it was nice to hear the Expert, hope you will find time when I come with new ask about BCB.
0
 
LVL 16

Expert Comment

by:George Tokas
ID: 38394335
>>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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Several part series to implement Internet Explorer 11 Enterprise Mode
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

755 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question