0
我有下面的字符串我想解析它!Android如何解析CDATA TAG?
<?xml version="1.0" encoding="ISO-8859-1"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:GetDrinksResponse xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/">
<return xsi:type="xsd:xml">
<Details>
<id>1</id>
<Name>drinks1</Name>
<lid>1</lid>
<LName><![CDATA[ 151-Proof Rum]]></LName>
<lamount><![CDATA[12000]]></lamount>
<dmid>1</dmid>
<mname><![CDATA[Apple Juice]]></mname>
<mamount><![CDATA[2323]]></mamount>
<inid></inid>
<inName><![CDATA[]]>
</inName>
<inamount><![CDATA[]]>
</inamount>
<Glass>HighBall Glass</Glass>
<Directions>33</Directions>
<Condiment>22</Condiment>
</Details>
<Details>
<id>2</id>
<Name>Drnks2</Name>
<lid></lid>
<LName><![CDATA[ 101-Proof Bourbon]]></LName>
<lamount><![CDATA[12000]]></lamount>
<dmid>2</dmid>
<mname><![CDATA[Apple Juice]]></mname>
<mamount><![CDATA[25000]]></mamount>
<inid></inid>
<inName><![CDATA[]]>
</inName>
<inamount><![CDATA[]]>
</inamount>
<Glass>Cocktail Glass</Glass>
<Directions>ss</Directions>
<Condiment>sd</Condiment>
</Details>
<Details>
<id>3</id>
<Name>Gimlet</Name>
<lid></lid>
<LName><![CDATA[ 151-Proof Rumsssssssss]]></LName>
<lamount><![CDATA[1s]]></lamount>
<dmid>3</dmid>
<mname><![CDATA[Apple Juice]]></mname>
<mamount><![CDATA[1]]></mamount>
<inid></inid>
<inName><![CDATA[]]>
</inName>
<inamount><![CDATA[]]>
</inamount>
<Glass>Regular</Glass>
<Directions>sadasd</Directions>
<Condiment>asd</Condiment>
</Details>
<Details>
<id>4</id>
<Name>Drinlks3</Name>
<lid></lid>
<LName><![CDATA[ 151-Proof Rumsssssssssssss]]></LName>
<lamount><![CDATA[12000]]></lamount>
<dmid>4</dmid>
<mname><![CDATA[Apple Juice]]></mname>
<mamount><![CDATA[2323]]></mamount>
<inid></inid>
<inName><![CDATA[]]>
</inName>
<inamount><![CDATA[]]>
</inamount>
<Glass>Regular</Glass>
<Directions>33</Directions>
<Condiment>22</Condiment>
</Details>
<Details>
<id>5</id>
<Name>Dr Abu Julianah</Name>
<lid></lid>
<LName><![CDATA[ 151-Proof Rum]]></LName>
<lamount><![CDATA[sss]]></lamount>
<dmid>5</dmid>
<mname><![CDATA[Apple Juice]]></mname>
<mamount><![CDATA[2323]]></mamount>
<inid></inid>
<inName><![CDATA[]]>
</inName>
<inamount><![CDATA[]]>
</inamount>
<Glass>Cocktail Glass</Glass>
<Directions>33</Directions>
<Condiment>22</Condiment>
</Details>
<Details>
<id>6</id>
<Name>Dr Abu</Name>
<lid></lid>
<LName><![CDATA[ 151-Proof Rum]]></LName>
<lamount><![CDATA[12000]]></lamount>
<dmid>6</dmid>
<mname><![CDATA[Apple Juicesssssss]]></mname>
<mamount><![CDATA[sddddddd]]></mamount>
<inid></inid>
<inName><![CDATA[]]>
</inName>
<inamount><![CDATA[]]>
</inamount>
<Glass></Glass>
<Directions>33</Directions>
<Condiment>22</Condiment>
</Details>
<Details>
<id>7</id>
<Name>Gimlet</Name>
<lid></lid>
<LName><![CDATA[ 1Testliquers]]></LName>
<lamount><![CDATA[12000]]></lamount>
<lid></lid>
<LName><![CDATA[sdffds]]></LName>
<lamount><![CDATA[dsdf]]></lamount>
<dmid>7</dmid>
<mname><![CDATA[Apple Juiceaaaaaaaaa]]></mname>
<mamount><![CDATA[aaaaaaaaaaaaa]]></mamount>
<dmid>8</dmid>
<mname><![CDATA[7-Up]]></mname>
<mamount><![CDATA[2323]]></mamount>
<inid>1</inid>
<inName><![CDATA[]]>
</inName>
<inamount><![CDATA[]]>
</inamount>
<inid>2</inid>
<inName><![CDATA[]]>
</inName>
<inamount><![CDATA[]]>
</inamount>
<Glass>Regular</Glass>
<Directions></Directions>
<Condiment></Condiment>
</Details>
</return>
</ns1:GetDrinksResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
這裏是我的代碼和響應高於XML字符串........... 如何在解析器和請給我處理類........... .....
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
ExampleHandler myExampleHandler = new ExampleHandler();
xr.setContentHandler(myExampleHandler);
xr.parse(new InputSource(response.toString()));
ParsedExampleDataSet parsedExampleDataSet = myExampleHandler
.getParsedData();
異常:::
java.io.FileNotFoundException:
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at DrinkParser.executeRequest(DrinkParser.java:105)
at DrinkParser.<init>(DrinkParser.java:64)
at DrinkParser.main(DrinkParser.java:149)
您編寫了哪些代碼來解析XML?你得到了什麼錯誤? – CanSpice
filenot發現異常,並可以讀取任何標籤,我從服務器解析,所以爲什麼FilenotFound也檢查此字符串來純粹........... –
看到我所有更新我的問題......... ........... –