Hello! There is a php script that sends an XML request to a specific port of a particular server using the POST method. On the server side there is a java daemon that accepts requests to this address. As a result, I get a string, for example, of the following form:

<?xml version="1.0"?><robox.rate.req><in_curr>EGZ</in_curr><out_curr>WMZ</out_curr><merchant_login>login</merchant_login><out_cnt>1</out_cnt></robox.rate.req> 

No spaces, tabs and line breaks. I read about XML parsers (SAX, JAXP), they are good, but they work only with .xml files. Is it possible to parse the string with some libraries that would conveniently represent the structure of the XML query and methods for working with them? Or do you have to manually pick out the values ​​from the triangular brackets, work with the string? Thank.

    1 answer 1

    Suddenly, I googled something:

     private static Document convertStringToDocument(String xmlStr) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder; try { builder = factory.newDocumentBuilder(); Document doc = builder.parse( new InputSource( new StringReader( xmlStr ) ) ); return doc; } catch (Exception e) { e.printStackTrace(); } return null; }