import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File;
import org.w3c.dom.*;
public class XmlStr {
  public String exchange() { 
  File docFile = new File("user_exchange.xml");
  Document newdoc = null;
  try {
         DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
         DocumentBuilder db = dbf.newDocumentBuilder();
         newdoc = db.newDocument();
      } catch (Exception e) {
          System.out.print("Problem parsing the file.");
     }
//建根节点
Element newRoot = newdoc.createElement("usin");
//为根节点加属性
newRoot.setAttributeNode(newdoc.createAttribute("ercd"));
//为属性赋值
newRoot.setAttribute("ercd","7");
//为节点赋值
newRoot.appendChild(newdoc.createTextNode(""));
//结束
newdoc.appendChild(newRoot);
String strValue = "<?xml version='1.0'?>"+newRoot.toString();
return strValue;
}
}
你要先写一个XML文件,那样结构要清晰些,上面的文件要具体修改一下,我用的是DOM的构造方法,用的是JDK1.3.1及JAXP解析,试试吧。

解决方案 »

  1.   

    这样可以不,先把这样的文本数据整理成一定的格式,然后导入到数据库的某表中,然后利用SQL语句以XML格式输出保存。
      

  2.   

    大哥:如何写啊!给段代码look look!要求用jdom
      

  3.   

    AnyJack(潜梦)的说法我现在用的就是这种方法!我想知道有没有更好的方法!
      

  4.   

    这个数据要生成什么样子的xml,能不能给个例子
      

  5.   

    这是一个包结构定义的文档 要求写成如下形式,当然也可以其他只要结构清晰,方便读写就可以
    USIN ---登陆包
     +RGCD  -包含属性值
     +TSRG  -.....
     .
     .
    USIN2  --登陆返回包
     +ERCD -包含属性值
     +SYDT 
     ..
      

  6.   

    给我email,原码较长,我给你发过去