4

I’ve been googling but can’t seem to find information on this… I think it’s possible because I remember seeing something about this. I’m already using xercesc to parse a XML document (using SAX2). I wanted to replace libcurl with xerces for the HTTP request I’m performing (this HTTP request returns the XML I need to parse). As I said, I googled around and can’t seem to find an example of how to accomplish this. I’ve also looked into the library documentation, but I’m unsure as to which classes I should use. Can anyone help me out with this? Is it possible?

Thanks!

1 Answers1

0

1: Include following header:

#include <xercesc/framework/URLInputSource.hpp>

2: Create instance of URLInputSource by passing http url as an argument:

URLInputSource src( "http://localhost:8080/sampledata-basic.xml" );

3: Pass this instance to "parse" method:

SAXParser* parser = new SAXParser;
//few more statements may go here
parser->parse(src);

NOTE: By default it will not support "https" url. If you want that functionality you need to rebuild the xerces with curl or winsock etc. see: http://xerces.apache.org/xerces-c/build-3.html for build options.

Icarus3
  • 2,310
  • 14
  • 22
  • @user3124955 I tested this with official xerces sample "SAXPrint". I simply changed the "xmlPath" variable to my hardcoded url and created "URLInputSource" instance with it. And instead of passing "xmlPath" to "parse" method, I passed "URLInputSource" instance and that did a trick. – Icarus3 Jul 29 '14 at 13:36
  • I've been trying to make this work for the past hour, but can't seem to accomplish this. I'm checking the variable state using a debug and everything seems fine. I have the following code: http://pastebin.com/httyvKi4 – user3124955 Jul 29 '14 at 13:36
  • I took too long to edit... Can you please look at the code I posted? Do I need to use the SAXParser class? – user3124955 Jul 29 '14 at 13:38
  • I just tried that url. I got this: "" unsupported protocol error. Also, in your code, I made one change which is I tried passing that url directly to URLInputSource. i.e. try skipping XMLURL instance. – Icarus3 Jul 29 '14 at 13:48
  • @user3124955 Sorry, forget about above comment. That was me creating "SAXPrintHandlers" in wrong manner. Could you please post your complete code ? or you could try putting your code in "SAX2Print" sample – Icarus3 Jul 29 '14 at 13:55
  • I have also tried that to pass the URL directly to URLInputSource. It still didn't work. Where did you saw the unsupported protocol error? In std::out? – user3124955 Jul 29 '14 at 13:58
  • I have tried your url with SAX2Print sample and I got that error on console. There seems to be some encoded content in that xml. Just to be sure I changed the url and point it to different one ( http://www.w3schools.com/xml/note.xml ) and it worked. I suggest first get your stuff working for some other xml url and then try to solve your encoding problem later. – Icarus3 Jul 29 '14 at 14:11
  • Ohh I got it, its "https" in the url which is causing the problem. – Icarus3 Jul 29 '14 at 14:18
  • You are right, I substituted the URL for the one you provided in the code I showed you and it works! Unfortunately, this XML is taken directly from the Google Maps API. Could this be because you're accessing a .xml file from w3schools and when using the Gmaps Directions APIs I'm just actually querying the API and it returns XML text? – user3124955 Jul 29 '14 at 14:22
  • How is the HTTPS protocol causing problems? How did you arrive to that conclusion? EDIT: Just saw your edit... Thanks for all the help, but I can't use regular HTTP (restrictions of the API). Also, compiling with curl is not an option (I prefer to use libcurl for that instead). Is there no way to use xercesc with https? – user3124955 Jul 29 '14 at 14:24
  • No way I guess. Dealing with https requires implementation of ssl/tls protocol. I am not surprised if xerces has pushed that responsibility over different net accessors. – Icarus3 Jul 29 '14 at 14:50