On 2/12/2014 8:21 AM, Eric_Peng wrote: > I was just trying to use SolrJ Client to import XML data to Solr server. And > I read SolrJ wiki that says "SolrJ lets you upload content in XML and Binary > format" > > I realized there is a XML parser in Solr (We can use a dataUpadateHandler in > Solr default UI Solr Core "Dataimport") > > So I was wondering how to directly use solr xml parser to upload xml by > using SolrJ Java Code? I could use other open-source xml parser, But I > really want to know if there is a way to call Solr parser library. > > Would you mind send me a simple code if possible, really appreciated. > Thanks in advance. > > solr/4.6.1
When the docs say that SolrJ lets you upload data in XML and binary format, what they actually mean is that SolrJ will create an update request that is formatted using XML, not that it will let you send arbitrary XML data. It is referring to the specific XML format shown here: http://wiki.apache.org/solr/UpdateXmlMessages#add.2Freplace_documents As for an XML parser ... SolrJ's "XMLResponseParser" is a class that accepts XML *responses* from Solr and translates them into the Java response object. There is also BinaryResponseParser. The only things that I am aware of in Solr that will deal with XML as the data source are the XPathEntityProcessor in the dataimport handler and the ExtractingRequestHandler which uses Apache Tika. Both of these are actually contrib modules -- jar files for these features are in the download, but not built into Solr or SolrJ. If you are using the extracting request handler, you could probably use the DirectXmlRequest object, where 'xml' is a String with the xml in it: DirectXmlRequest req = new DirectXmlRequest( "/update/extract", xml ); ModifiableSolrParams params = new ModifiableSolrParams(); params.set("someParam", "someValue"); req.setParams(params); NamedList<Object> response = solrServer.request(req); I hope that you are right and there actually is an XML parser built into SolrJ. We would both learn something. Thanks, Shawn