Android getting XML values
I have the following XML code, which I got by a UPnP device and like to get the res value - the RTSP URL. In this case rtsp://10.42.0.103:554/live.sdp
How can I do this? I heard that Android has some built-in support for reading XML. Is that true?
<DIDL-Lite xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/">
<item id="11" parentID="1" restricted="1">
<dc:title>Network Camera Stream 1</dc:title>
<upnp:class&g开发者_运维问答t;object.item.videoItem</upnp:class>
<res protocolInfo="rtsp-rtp-udp:*:video/mpeg4-generic:*" resolution="640x480">rtsp://10.42.0.103:554/live.sdp</res>
</item>
<item id="12" parentID="1" restricted="1">
<dc:title>Network Camera Stream 2</dc:title>
<upnp:class>object.item.videoItem</upnp:class>
<res protocolInfo="rtsp-rtp-udp:*:video/mpeg4-generic:*" resolution="176x144">rtsp://10.42.0.103:554/live2.sdp</res>
</item>
</DIDL-Lite>
You may probably be looking for a SAX-Parser:
http://developer.android.com/reference/javax/xml/parsers/SAXParser.html
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
parser.parse(xml, yourXMLHandler);
Well, thanks for your help. SAX is in my opinion too much overhead for this small file. It's much easier with an XMLPullParser ... you don't have to deal with this event stuff and can quickly pick up some keywords ...
http://developer.android.com/reference/org/xmlpull/v1/XmlPullParser.html
精彩评论