ITeye博客

XML

共 5 篇文章

DOM4J解析XML文档

DOM4J解析XML文档实例: public static void main(String[] args) throws IOException { //第一种方式创建文档并设置根元素节点 /*Document document = DocumentHelper.createDocument(); Element root = DocumentHelper.createElement("student"); document.setRootElement(root);*/ //第二种方式,创建文档并设置根节点 Element root = DocumentHelper.createElem…

2011-05-17 01:06 · XML · XML

JDOM解析XML

JDOM生成XML文档:(文档的输出) public static void main(String[] args) throws IOException, IOException { Document document = new Document(); Element root = new Element("root"); document.addContent(root); //添加注释 Comment comment =new Comment("this is my comments"); root.addContent(comment); Element e = new Eleme…

2011-05-16 23:54 · XML · C · C++ · C# · XML

SAX解析XML文档

SAX(Sample APIs for XML)采用顺序访问XML文档的方式来解析。 public static void main(String[] args) throws Exception, SAXException { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); parser.parse(new File("dom.xml"), new MyHandler()); } } class MyHandler extends De…

2011-05-16 22:44 · XML · XML

DOM解析XML文档

利用DOM解析技术,将外部XML文档全部内容解析出来按原格式输出: public static void main(String[] args) throws Exception { //获得DOM解析器工厂 DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance(); //获得DOM解析器 DocumentBuilder db=dbf.newDocumentBuilder(); //获得DOM对象 Document document =db.parse(new File("dom.xml")); //获得XMl根元素节点 …

2011-05-16 20:06 · XML · XML

XML总结

当XML文件使用非Unicode编码时,必须在XML文档声明中指定其字符集编码,而采用Unicode编码时则可以在XML声明文档中省略字符集编码。只有在实在不能使用UTF-8或UTF-16编码文本文件时,才应考虑使用本地字符集。 如果在一个元素中没有嵌套子元素和数据,也就是标记对之间没有内容,这样的元素称为空元素。空元素可以不使用结束标记,但必须在起始标记的结束定界符(>)前面增加一个正斜杠(/)字符来说明该标记是一个空元素,空元素标记一般都与属性配合使用,例如<img src="img.jgp" /> XML元素不允许使用标签交叉,所有元素必须合理嵌套。例如:<b>welcome to <…

2011-04-11 13:10 · XML · CSS · XML