加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

java.net.MalformedURLException: no protocol解决方法

(2013-09-18 18:29:06)
标签:

xml

xpath

no_protocol

android乱码

分类: xml

原帖:http://www.joyphper.net/article/201204/146.html


好久没写博客了    

今天在做java解决xml字符串的时候碰到的一个问题

出问题的代码如下:


  1. String xml="<?xml version="1.0"?>......."; //此处xml是通过接口获取到的xml字符串
  2. DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
  3. DocumentBuilder builder=factory.newDocumentBuilder();
  4. Document doc = builder.parse(xml);

 

运行的时候报java.net.MalformedURLException: no protocol

 经过google查找后无果,只是有些问题上提到了有中文的问题,后来想到是不是因为请求过的编码问题,结果与自己的想象的完全一致,经过转码后问题解决 

 


  1. String xml="<?xml version="1.0"?>......."; //此处xml是通过接口获取到的xml字符串
  2. DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
  3. DocumentBuilder builder=factory.newDocumentBuilder();
  4. Document doc = builder.parse(new InputSource(new ByteArrayInputStream(xml.getBytes("utf-8"))));

 

后来想想,是不是因为在xml字符串中没有指定编码的问题呢,具体问题没有寻根究底了。。。


InputStream inStr = new GZIPInputStream(con.getInputStream());

有的流是被压缩过的,需要解压后读取.

con.getContentEncoding() 记得看流的编码

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有