xml标签内容获得迷惑
来源:互联网 发布:android算法面试题 编辑:程序博客网 时间:2024/06/07 00:24
package com.suning.ebuy.vgs.airticket.globalImpl;
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import com.xiao.demo.utils.XmlUtils;
public class XmlTest {
public static void main(String[] args) throws ParserConfigurationException,
SAXException, IOException, Exception {
// TODO Auto-generated method stub
String xml = "<Prices><Price><PsgType>ADT</PsgType></Price><Price><PsgType>CHD</PsgType></Price></Prices>";
Document doc = XmlUtils.getW3CDom(xml);
NodeList nodeList = XmlUtils.runXpath(doc, "//Prices/Price", null);
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
getPrices(node);
}
}
public static void getPrices(Node node,int i) {
String pricesXml = XmlUtils.nodeAsString(node);
System.err.println(pricesXml);
String psgType = XmlUtils.getValueByXpath(node, "//Price/PsgType");
System.err.println("乘客类型:" + psgType);
}
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import com.xiao.demo.utils.XmlUtils;
public class XmlTest {
public static void main(String[] args) throws ParserConfigurationException,
SAXException, IOException, Exception {
// TODO Auto-generated method stub
String xml = "<Prices><Price><PsgType>ADT</PsgType></Price><Price><PsgType>CHD</PsgType></Price></Prices>";
Document doc = XmlUtils.getW3CDom(xml);
NodeList nodeList = XmlUtils.runXpath(doc, "//Prices/Price", null);
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
getPrices(node);
}
}
public static void getPrices(Node node,int i) {
String pricesXml = XmlUtils.nodeAsString(node);
System.err.println(pricesXml);
String psgType = XmlUtils.getValueByXpath(node, "//Price/PsgType");
System.err.println("乘客类型:" + psgType);
}
}
上面的类运行的结果你会猜到么?
<?xml version="1.0" encoding="UTF-8"?><Price><PsgType>ADT</PsgType></Price>
乘客类型:ADT
<?xml version="1.0" encoding="UTF-8"?><Price><PsgType>CHD</PsgType></Price>
乘客类型:ADT
就这个结果让我想了好久,也曾试着跟进去看看代码的实现,不过恕我本人愚笨,未曾找到,
但就此结果让我甚是想不通。纠结了很久。如果你也想知道答案的话,下篇文章会有答案的,
不过还是希望看到的人能独立思考下。大家可以交流下心得
- xml标签内容获得迷惑
- js获得html中的input标签内容
- xml,html 迷惑
- 如何获得XML文件中的内容?
- PHP以数组形式获得XML内容
- 获得xml节点,节点属性,节点内容
- 去除xml标签,抽取文本内容
- 解析xml文件的标签内容
- struts.xml配置文件的内容标签
- java读取xml指定标签的内容
- struts.xml配置文件的内容标签
- 如何获得web.xml里面的<context-param>内容
- 迷惑
- 迷惑
- 迷惑
- 迷惑
- 迷惑
- 迷惑
- Java_Servlet入门教程
- android在特定情况下显示按钮
- Python:BOA 可视开发环境
- JUint学习笔记12---对servlet和filter进行单元测试1
- 关于COM中变体类型VARIANT
- xml标签内容获得迷惑
- C++虚函数的深入理解
- Linux(CentOS)下VSFTP服务的配置
- libgdx 使用particle editor导出文件后在android中载入不显示问题
- MFC中ComboBox的用法
- Oracle 删除用户和表空间
- ibatis与spring的集成
- 动态规划之最长递增子序列
- Linux 内核中的 cdev_alloc和cdev_add