【转】+【改】DOM4J处理XML带有命名空间的四种方法
当你解析XML时,是否会因为命名空间的存在而不能得偿所愿呢?
java方面,好多人推荐用dom4j处理xml,我也就说说在dom4j上处理带命名空间的xml
xml代码example: 再说前三种方法,也是从网上看来的。http://www.cnblogs.com/patrickchen/articles/1188920.html
D: eport.css
第一个方案.设置你的xpath的命名空间setNamespaceURIs
1: public class TransferXML { 2: public static void main(String[] args) throws Exception{ 3: Map map = new HashMap(); 4: map.put("design","http://www.eclipse.org/birt/2005/design"); 5: SAXReader saxReader = new SAXReader(); 6: File file = new File("D:\test.xml"); 7: Document document = saxReader.read(file); 8: XPath x = document.createXPath("//design:list-property"); 9: x.setNamespaceURIs(map); 10: List nodelist = x.selectNodes(document); 11: System.out.println(nodelist.size()); 12: } 13: }
第二个解决方案:设置你的DocumentFactory()的命名空间 setXPathNamespaceURIs
1: public class TransferXML { 2: public static void main(String[] args) throws Exception{ 3: Map map = new HashMap(); 4: map.put("design","http://www.eclipse.org/birt/2005/design"); 5: SAXReader saxReader = new SAXReader(); 6: File file = new File("D:\test.xml"); 7: saxReader.getDocumentFactory().setXPathNamespaceURIs(map); 8: Document document = saxReader.read(file); 9: List tmp = document.selectNodes("//design:list-property"); 10: System.out.println(tmp.size()); 11: } 12: }
第三种方法:本人用的,最笨也是最通用的方法,就是不使用开发环境给你提供的一系列对象,而是用XPath语法中自带的local-name() 和 namespace-uri() 指定你要使用的节点名和命名空间。
当你遇到使用xslt来样式化xml时,就知道这个笨方法的好处了:
1: public class TransferXML { 2: public static void main(String[] args) throws Exception 3: SAXReader saxReader = new SAXReader(); 4: File file = new File("D:\test.xml")
相关文档:
技术介绍
在一般的Java项目中,生成word文档的时候,我们会使用到jacob来作为我们生成word文档的工具,但是jacob是通过使用JNI调用dll文件来实现,这样的工作方式带来了极大的性能开销.这里我们采用Velocity+zip+xml快速构建word2007文档,所以说这个技术实现有一定的局限性,生成的必须是word2007文档 ......
方法一:
采取通用的base64编码方式,取时解码存时加码。
毛老师提供了完整的编码代码,且效率很高。
unit Base64;
interface
uses SysUtils, Classes;
type
{$IFDEF UNICODE}
Base64String = AnsiString;
{$ELSE}
Base64String = strin ......
JAVA对象转换为XML格式
简单的颤述下如何将JAVA对象转换为XML格式,详细了解请进入http://xstream.codehaus.org/tutorial.html
JAVABEAN对象
userInfo.java
private String name;
& ......
Integration with the XML Data Type
With the introduction of the XML data type, we wanted to also give FOR XML the ability to generate an instance of XML directly (more precisely, it generates a single row, single column rowset where the cell contains the XML data type instance).
Because of the bac ......
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Xml;
namespace jiu ......