xml解析

http://www.cbex.com.cn/unpub/bj.xml

http://www.cquae.com/unpub/pros.xml

第一种

Document doco;

DocumentBuilderFactory dbfo = DocumentBuilderFactory.newInstance();
dbfo.setCoalescing(true);
DocumentBuilder dbyo = dbfo.newDocumentBuilder();
doco = dbyo.parse(url);

NodeList nlo = doco.getElementsByTagName("pubPrice");
NodeList nllo = doco.getElementsByTagName("title");
NodeList n23o = doco.getElementsByTagName("link");
NodeList pubDate = doco.getElementsByTagName("pubDate");
NodeList proNo = doco.getElementsByTagName("proNo");
int numgp = 0;
if ((numgp++) < 3) {
if (nlo.getLength() > 0) {
for (int j = 0; j < nlo.getLength(); j++) {
String str1 = nlo.item(j).getFirstChild().getNodeValue();
Double str22 = Double.valueOf(str1);
DecimalFormat format = new DecimalFormat("0.000000");
String s = format.format(str22);
int xo = j + 1;
String str2 = n23o.item(xo).getFirstChild().getNodeValue();
int xy = j + 1;
String str3 = nllo.item(xy).getFirstChild().getNodeValue();
String sj = pubDate.item(j).getFirstChild().getNodeValue();
String bh = proNo.item(j).getFirstChild().getNodeValue();


Map<String, String> map = new HashMap<String, String>();
map.put("xmbh", bh);
map.put("name", str3);
map.put("href", str2);
map.put("price", s);
map.put("date", sj);


list.add(map);
}
}
}





第二种

Document doco;

StringBuffer result = new StringBuffer("");
URL connect = new URL(url.toString());
URLConnection connection = connect.openConnection();
connection.setDoOutput(true);
connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
connection.getInputStream();
String line;
while ((line = reader.readLine()) != null) {
result.append(line);
result.append("\r\n");
}


StringReader sr = new StringReader(result.toString());
InputSource is = new InputSource(sr);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
doco = builder.parse(is);
line = null;
sr.close();


NodeList nlo = doco.getElementsByTagName("pubPrice");
NodeList nllo = doco.getElementsByTagName("title");
NodeList n23o = doco.getElementsByTagName("link");
NodeList pubDate = doco.getElementsByTagName("pubDate");
NodeList proNo = doco.getElementsByTagName("proNo");
int numgp = 0;
if ((numgp++) < 3) {
if (nlo.getLength() > 0) {
for (int j = 0; j < nlo.getLength(); j++) {
String str1 = nlo.item(j).getFirstChild().getNodeValue();
Double str22 = Double.valueOf(str1);
DecimalFormat format = new DecimalFormat("0.000000");
String s = format.format(str22);
int xo = j + 1;
String str2 = n23o.item(xo).getFirstChild().getNodeValue();
int xy = j + 1;
String str3 = nllo.item(xy).getFirstChild().getNodeValue();
String sj = pubDate.item(j).getFirstChild().getNodeValue();
String bh = proNo.item(j).getFirstChild().getNodeValue();


Map<String, String> map = new HashMap<String, String>();
map.put("xmbh", bh);
map.put("name", str3);
map.put("href", str2);
map.put("price", s);
map.put("date", sj);


list.add(map);
}
}
}


posted @   silentmuh  阅读(38)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
Live2D
欢迎阅读『xml解析』
  1. 1 Walk Thru Fire Vicetone
  2. 2 爱你 王心凌
  3. 3 Inspire Capo Productions - Serenity
  4. 4 Welcome Home Radical Face
  5. 5 粉红色的回忆 李玲玉
Walk Thru Fire - Vicetone
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.

作词 : Van Der Voort, Joren Johannes

作曲 : Victor Pool/Justin Gammella/Ruben Christopher den Boer/Meron Mengist/Joren van der Voort

Talk to me

Spill the secrets you've been keeping

Life cuts deep

Let me help pick up the pieces

You're not alone, I'm by your side

Don't you know, don't you know

I'll walk through fire with you

I'll walk through fire

No matter what, I'll make it right

Don't you know, don't you know

I'll walk through fire with you

I'll walk through fire

I'm not an angel, I'm not a saint

I've been a closed book full of mistakes

But when you're broken, when you're in pain

Oooh, ooh

I'll walk through fire with you

I'll walk through fire

I'll walk through fire with you

I'll walk through fire

You know I

Don't pretend to be a savior

But let me in, yeah

I promise nobody can break us

You're not alone, I'm by your side

Don't you know, don't you know

I'll walk through fire with you

I'll walk through fire

No matter what, I'll make it right

Don't you know, don't you know

I'll walk through fire with you

I'll walk through fire

I'm not an angel, I'm not a saint

I've been a closed book full of mistakes

But when you're broken, when you're in pain

Oooh, ooh

I'll walk through fire with you

I'll walk through fire with you

I'll walk through fire

I'll walk through fire with you

I'll walk through fire with you

You're not alone, I'm by your side

Don't you know, don't you know

I'll walk through fire with you

I'll walk through fire

I'm not an angel, I'm not a saint

I've been a closed book full of mistakes

But when you're broken, when you're in pain

Oooh, ooh

I'll walk through fire with you

I'll walk through fire with you

I'll walk through fire

I'll walk through fire with you

I'll walk through fire with you

点击右上角即可分享
微信分享提示