我正在使用黑莓中的xml。 我目前正在使用一个xml字符串,其中一个值是另一个xml字符串。 问题是,当其他值被整齐地提取出来时,xml值不是。 只有“<”正在从节点中提取。从黑莓中的另一个XML字符串中提取嵌入的XML并在黑莓中解码xml
一样,似乎是在正常的java工作。 唯一的区别我可以看到的是在该请求被视为方式:
在Java项目:
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "text/xml;charset=UTF-8");
connection.setRequestProperty("Content-Length", "" + Integer.toString(resultText.getBytes().length));
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
wheras,黑莓用途:
http.setRequestMethod(HttpConnection.POST);
http.setRequestProperty("User-Agent","Blackberry 8320/4.2.2 Profile/MIDP-2.0 Configuration/CLDC-1.1");
http.setRequestProperty("x-rim-transcode-content", "none");
http.setRequestProperty("Content-Type", "text/xml;charset=UTF-8");
http.setRequestProperty("Content-Length","" + Integer.toString(resultText.getBytes().length));
和下面的代码是用于获得Java中的Web服务:: 的响应:
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
String line;
StringBuffer response = new StringBuffer();
while ((line = rd.readLine()) != null) {
response.append(line);
response.append('\r');
}
rd.close();
in BB
InputStream inStream = http.openInputStream();
// Get the length and process the data
int len = (int) http.getLength();
if (len > 0)
{
int actual = 0;
int bytesread = 0;
byte[] data = new byte[len];
while ((bytesread != len) && (actual != -1)) {
actual = inStream.read(data, bytesread, len - bytesread);
bytesread += actual;
}
String recd = new String(data, "UTF-8");
responseData = recd;
除了这个改变,我看不出有任何其他的不同。嵌入式XML获取一个Java项目完美提取,但BB项目只提取“<” :-(
任何帮助,将不胜感激。
被解析的XML文件是在这里:(没有。提供完整的一个已删除所有,但在嵌入式XML一个值
response:::::<?xml version="1.0" encoding="UTF-8"?><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.o rg/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://sche mas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:glwsdl"><SOAP-ENV:Body><return xsi:type="SOAP-ENC:Arr ay" SOAP-ENC:arrayType="tns:CrosswordItem[1]"><item xsi:type="tns:CrosswordItem"><Date xsi:type="xsd :string">2012-01-04</Date><Crossword xsi:type="xsd:stri ng"><?xml version="1.0" encoding="UTF-8"?>
<crossword size="7">
<grid>
<cell position="5_6" value="&#xAB0;&#xABE;"/>
<cell position="6_6" value="&#xAA8;"/>
</grid>
<horizontalkeys>
<key number="19" position="3_6" length="4" answer="&#xA9 C;&#xABE;&#xAAB;&#xAB0;&#xABE;&#xAA8;" question="&#xA95;&#xAC7 ;&#xAB8;&#xAB0;"/>
</horizontalkeys>
<verticalkeys>
<key number="17" position="6_5" length="2" answer="&#xAA E;&#xABE;&#xAA8;" question="&#xA86;&#xAAC;&#xAB0;&#xAC2;, &#xA AA;&#xACD;&#xAB0;&#xAA4;&#xABF;&#xA B7;&#xACD;&#xAA0;&#xABE;"/>
</verticalkeys>
</crossword>
</Crossword><Gridsize xsi:type="xsd:string">7</Gridsize><Id xsi:type="xsd:string">63</Id></item></re turn></SOAP-ENV:Body></SOAP-ENV:Envelope>
编辑: 我部分地解决了这个问题:使用 :
xmlEmbeddedData = xmlData.substring(xmlData.indexOf("<?xml version="1.0"encoding="UTF-8"?>"), xmlData.indexOf("</Crossword>"));
我设法将我需要的东西提取到另一个字符串中,带有一个问题,我需要解析的xml字符串,现在包含:“& g t; “for”,“& lt;”为<和“& q u o t; &放大器;” ......无空格...
我需要解码的字符串,并返回一个XML字符串,我可以解析 有人可以帮
最后一点:嵌入式XML字符串是CDATA。 – s5v 2012-02-06 10:15:42