C++ (Qt)using namespace boost::network;using namespace boost::network::http; client::request request_("http://127.0.0.1:8000/");request_ << header("Connection", "close");client client_;client::response response_ = client_.get(request_);std::string body_ = body(response_);
C++ (Qt)namespace pt = boost::property_tree; pt::ptree xml;pt::read_xml( "file.xml", xml ); string v = xml.get<string>( "producer.item.<xmlattr>.name" );int v = xml.get<int>( "producer.item.v" );double d = xml.data<double>( "producer.item.d" );
Javaimport org.w3c.dom.Document;import org.xml.sax.SAXException; import javax.xml.parsers.DocumentBuilder;import javax.xml.parsers.DocumentBuilderFactory;import javax.xml.parsers.ParserConfigurationException;import javax.xml.xpath.XPath;import javax.xml.xpath.XPathExpressionException;import javax.xml.xpath.XPathFactory;import java.io.ByteArrayInputStream;import java.io.IOException;import java.io.InputStream; public class Solution{ public static void main(String[] args) throws ParserConfigurationException, IOException, SAXException, XPathExpressionException { String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<!DOCTYPE avset-list>" + "<avset-list ver=\"1.0\">" + "<producer name=\"Fuck, Inc\">" + "<item name=\"Good shit\">" + "<v>79</v>" + "<d>8,0</d>" + "</item>" + "</producer>" + "</avset-list>"; try(InputStream is = new ByteArrayInputStream(xml.getBytes())) { DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = documentBuilder.parse(is); XPath xpath = XPathFactory.newInstance().newXPath(); Object elements[] = { xpath.evaluate("/avset-list/producer/item/@name", doc), xpath.evaluate("/avset-list/producer/item/v", doc), xpath.evaluate("/avset-list/producer/item/d", doc) }; for(Object element : elements) { System.out.println(element); } } }}