KaLuoTe  
公告


日历
<2006年3月>
2627281234
567891011
12131415161718
19202122232425
2627282930311
2345678
统计
  • 随笔 - 4
  • 文章 - 0
  • 评论 - 0
  • 引用 - 0

导航

常用链接

留言簿(1)

随笔分类(1)

随笔档案(4)

搜索

  •  

最新随笔

最新评论

阅读排行榜

评论排行榜

 

Example1: ["Valid" XML Document]

["Valid" XML Document  .dtd]

     <! ELEMENT NetProLan (type, ex+) >
    
<! ELEMENT type (#PCDATA) >
    
<! ELEMENT ex (#PCDATA) >


["Valid" XML Document  .xml]

<? xml version="1.0" encoding="gb2312" ?>
    
<! DOYTYPE NetProLan SYSTEM "test.dtd" >
    
< NetProLan >
        
< type > tag </ type >
            
< ex > html </ ex >
            
< ex > shtml </ ex >
        
< type > meta </ type >
            
< ex > xml </ ex >
            
< ex > sgml </ ex >
            
< ex > lixin </ ex >
    
</ NetProLan >





Example2: ["WellFormed" XML Document ]
<?xml version="1.0" encoding="gb2312" standalone="yes"?>
    
<NetProLan>
        
<type>tag</type>
            
<ex>html</ex>
            
<ex>shtml</ex>
        
<type>meta</type>
            
<ex>xml</ex>
            
<ex>sgml</ex>
            
<ex>lixin</ex>
    
</NetProLan>





Example3: [ JavaScripte access xml ]
<script language="javascript" for="window" event="onload">
        
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async
="false";      //Parser after all files loaded
        xmlDoc.load("test.xml");
        nodes
=xmlDoc.documentElement.childNodes;
        title.innerText
=nodes.item(0).text;
        author.innerText
=nodes(1).text;
        date.innerText
=nodes(2).text;
    
</script>

//xmlDoc.load(".xml")是载入文件 | xmlDoc.loadXML(text)载入String





Example4:  { Java access xml }

[.xml]

<?xml version="1.0" encoding="GB2312"?>
    
<gogogo>
        
<user>
            
<name>lixin</name>
            
<sex>M</sex>
            
<Niu>T</Niu>
        
</user>
        
<user>
            
<name>xinli</name>
            
<sex>MM</sex>
            
<Niu>TT</Niu>
        
</user>
    
</gogogo>


[Use DOM]






Example4:  { Java access xml  Use Dom4j }

 1/**
 2 * 不考虑移植性的情况下,dom4j在java和xml互操作方面性能
 3 * 优于Dom 和SAX; 
 4 * @author Pp
 5 *
 6 */

 7import java.io.File;
 8import org.dom4j.Document;
 9import org.dom4j.Element;
10import org.dom4j.io.SAXReader;
11import java.util.Iterator;
12
13public class TestDom4j {
14    /**
15     * @param args
16     */

17    public static void main(String[] args) {
18        // TODO Auto-generated method stub
19        try {
20            File f = new File("D:\\eclipse\\WS\\testXML\\user.xml");
21            SAXReader saxR = new SAXReader();
22            Document doc = saxR.read(f);
23            Element el = doc.getRootElement();
24            System.out.println(el.getName());
25            Element tempEle;
26            Iterator it= el.elementIterator("user");
27            while(it.hasNext() ) {
28                tempEle = (Element)it.next();
29                System.out.println(tempEle.elementText("name")+ "\t" + tempEle.elementText("sex"));
30            }

31        }
catch(Exception e) {e.printStackTrace();}
32    }

33
34}

35




posted on 2006-03-28 23:17 KaLuoTe 阅读(242) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航:
 
 
Copyright © KaLuoTe Powered by: 博客园 模板提供:沪江博客