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>
parser = new XmlPullParcer(); String prodTag = "producer"; String itemTag = "item"; String vTag = "v"; String dTag = "d"; while ((event = parser.next()) != XmlPullParser.END_DOCUMENT) { if (event == XmlPullParser.START_TAG) { if (prodTag .equals(parser.getName())) { System.out.println("producer name:" + parser.getAttributeValue(null, "name")); } else if (itemTag.equals(parser.getName())) { System.out.println("item name:" + parser.getAttributeValue(null, "name")); } else if (vTag.equals(parser.getName())) { System.out.println("v: " + parser.nextText()); } else if (dTag.equals(parser.getName())) { System.out.println("d: " + parser.nextText()); } }
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" );
C++ (Qt)for( const pt::ptree::value_type &it : xml.get_child( "producer" ) ){ if( it.first == "item" ) { const pt::ptree &item = it.second; string v = item.get<string>( "<xmlattr>.name" ); int v = item.get<int>( "v" ); double d = item.data<double>( "d" ); }}
const pt::ptree &item = [b]it.second[/b];
for( const ValueType &it : xml.getChild("producer") ){ if( it.getKey == "item" ) { XmlItem &item = it.getValue(); String v = item.getName("name"); int v = item.getInt("v"); double d = item.getDouble("d"); }}
C++ (Qt) parser = new XmlPullParcer(); String prodTag = "producer"; String itemTag = "item"; String vTag = "v"; String dTag = "d"; while ((event = parser.next()) != XmlPullParser.END_DOCUMENT) { if (event == XmlPullParser.START_TAG) { if (prodTag .equals(parser.getName())) { System.out.println("producer name:" + parser.getAttributeValue(null, "name")); } else if (itemTag.equals(parser.getName())) { System.out.println("item name:" + parser.getAttributeValue(null, "name")); } else if (vTag.equals(parser.getName())) { System.out.println("v: " + parser.nextText()); } else if (dTag.equals(parser.getName())) { System.out.println("d: " + parser.nextText()); } }