易截截图软件、单文件、免安装、纯绿色、仅160KB

对于带有表空间xmlns的xml文件的解析

对于带有表空间xmlns的xml文件的解析,用正常解析文件的方法总是失效,不起作用,无法获得元素。
下面给出两种方法解析此类文件:
1.按正常解析xml文件的方法,需要注意几点:
获取元素Element,不可使用函数:document.selectNodes("//region");
只可以先取到根元素,一级一级往下取,eg:
Element root = document.getRootElement();
Element ele = root.element("head");
获取属性值,可以按一般的方法操作,eg:
List ll = document.selectNodes("//@regionName");
  System.out.println("ll.size=" + ll.size());
2.使用XPath。eg:
public void testHasNameSpace(File file) {
SAXReader saxReader = new SAXReader();
Document document = null;
// XmlDocument document=
try {
document = saxReader.read(file);
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
HashMap xmlMap = new HashMap();
xmlMap.put("smil", "http://www.w3.org/2000/SMIL20/CR/Language");
XPath x = document.createXPath("//smil:region");
x.setNamespaceURIs(xmlMap);
List regionList = x.selectNodes(document);
System.out.println("there are " + regionList.size() + " regions");
XPath att = document.createXPath("//smil:region/@regionName");
att.setNamespaceURIs(xmlMap);
List attrList = att.selectNodes(document);
System.out.println("there are " + attrList.size() + " attrs");
int i = 0;
Iterator it = attrList.iterator();
while (it.hasNext()) {
Attribute a = (Attribute) it.next();
System.out.println((i++) + "个:" + a.getValue());
}
}


相关文档:

使用 aspx 页面返回 xml 格式的值时,需要注意写法

解决了,是1楼说的方法,不能写成
context.Response.ContentType = "xml";
必须要是
context.Response.ContentType = "text/xml";
就OK了~
实例:
  Response.ContentType = "text/xml";
            Page.Response.Write("<?xml version=\"1.0\" ......

XML 语法规则


转自:http://www.w3school.com.cn/xml/xml_syntax.asp
XML 的语法规则很简单,且很有逻辑。这些规则很容易学习,也很容易使用。
所有 XML 元素都须有关闭标签
在 HTML,经常会看到没有关闭标签的元素:
<p>This is a paragraph
<p>This is another paragraph
在 XML 中,省略关闭标签是非法的。所有元 ......

Parsing XML from the Net Using the SAXParser


Parsing XML from the Net - Using the SAXParser
http://www.anddev.org/parsing_xml_from_the_net_-_using_the_saxparser-t353.html
What you learn:
You will learn how to properly parse XML
(here: from the net
) using a SAXParser
.
What it will look like:
Description:
0.)
In this tutorial we ......

DataSet序列化输出到XML(并指定输出XML标准)

 public partial class Form1 : Form
    {
        DataSet ds = new DataSet();
        public Form1()
        {
           ......

Expat XML解析器的介绍

互联网发展得很快,都是源自于使用了超文本的表达方式。比如你查看一篇文章,看到不懂的关键字,就可以通过链接去查看它的内容,看完之后再回来接着看原来的东西,这样比较适合学习的方式。使用HTML标记的文本,是结构化储存的,这样的表达方式才可以实现超级连接。由于HTML具有超强的表达能力,也就在互联网上生存下来,那 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号