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

通过DOM4J解析XML文件小结

创建XML文件:
public boolean createXML(){
  try{
   Document doc = DocumentHelper.createDocument();
   Element root = doc.addElement("root");
   Element personNode = root.addElement("person");
   Element sonNode = personNode.addElement("fristson");
   sonNode.setText("lk1");
   Element sonNode2 = personNode.addElement("secandtson");
   sonNode2.setText("lk2");
   
   OutputFormat opf = OutputFormat.createPrettyPrint();
   opf.setEncoding("GB2312");
   
   XMLWriter xmlw = new XMLWriter(new FileWriter("d:\\myXML.xml"),opf);
   xmlw.write(doc);
   
   xmlw.close();
   return true;
  }catch(Exception e){
   System.out.println("error: In create XML");
   return false;
  }
 }
以上只是个简单的创建了一个XML文件在D盘下,下边主要是分析XML文件,提取名字和内容:以JAVA项目中,经典的WEB.XML为例
public boolean updateXML(){
  Document doc = null;
  try{
   SAXReader sr = new SAXReader();
   doc = sr.read(new File("d:\\web.xml"));
   Element personRoot = doc.getRootElement();
   Iterator personNode = personRoot.elementIterator();
   while(personNode.hasNext()){
    Element sonNode = (Element)personNode.next();
    List sonNodes = sonNode.elements();
    System.out.println(sonNode.getName());
     for(int i = 0 ;i<sonNodes.size() ; i++){
      System.out.println(i+":"+((Element)sonNodes.get(i)).getName());
      System.out.println(i+":"+((Element)sonNodes.get(i)).getText());
     }


相关文档:

java 操作XML文件(片段)

//create a new Document
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document d = db.newDocument();

//add root Node
Element noteuser = d.createElement("note-users");
d.appendChil ......

XML Schema 中 import 和 include 的区别

XML Schema 中 import 和 include 的区别
XML Schema 允许将一个XSD文件分为几个文件存放,在必要时使用 import 或者 include 进行导入。这二者的区别是:
import:只能导入不同命名空间的XSD
include:只能导入相同命名空间的XSD,或被导入的XSD未声明命名空间
例子:
<xsd:import namespace=”http://acme ......

xml 读写

读:
//打开某文件(假设web.config在根目录中)
string filename=Server.MapPath("/") + @"WebApplication1\web.config";
XmlDocument xmldoc= new XmlDocument();
xmldoc.Load(filename);
//得到顶层节点列表
XmlNodeList topM=xmldoc.DocumentElement.ChildNodes;
foreach(XmlElement element in topM)
{
if(ele ......

.net中,读取XML在页面显示,布局用Repeater控件

 public static IList<News> GetAllNews()
        {
            XmlDocument xdoc = new XmlDocument();
            xdoc.Load("你读取的地址:例如 ......

[Perl]用XML::Simple解析XML文件

在Perl中解析XML的方法最常见的就是使用 XML::DOM
和 XML::Simple了。
XML::DOM过于庞大,而且解析结果是一个DOM树,操作也不方便。
对于小型且不复杂的XML文件,XML::DOM真是杀鸡用牛刀。
这时就轮到轻便的XML::Simple上场了。
XML::Simple如其名,真的很简单。假设XML内容如下:
<opt>
<user login= ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号