gpt4 book ai didi

Android如何解析CDATA TAG?

转载 作者:行者123 更新时间:2023-11-29 18:17:19 24 4
gpt4 key购买 nike

我有下面的字符串,我想解析它!!!!

<?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 字符串之上......................如何解析并请给我 Handler Class................................

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)

最佳答案

是的,问题已经解决了......

factory.setCoalescing(true);

DocumentFactory 和 CDATA 被删除,解析就像普通 XML 文件一样......

关于Android如何解析CDATA TAG?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7448496/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com