为什么不用工具呢?
用Relaxer很简单的啊。

解决方案 »

  1.   

    using saxit's very easy to do this
    郁闷中,只谈技术同美食
      

  2.   

    很简单亚,对每个元素挨个遍历不就完了.用jdom会很简单
      

  3.   

    import javax.xml.parsers.*;
    import org.w3c.dom.*;public class DOMTest {  public static void main(String[] args) throws Exception {
        DOMTest dt = new DOMTest(args[0]);
      }  public DOMTest(String uri) throws Exception {
        DocumentBuilderFactory factory =
            DocumentBuilderFactory.newInstance();
        factory.setValidating(true);
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document doc = builder.parse(uri);
        displayTree(doc.getDocumentElement());
      }  protected void displayTree(Node node) {
        short nodeType = node.getNodeType();
        switch (nodeType) {
          case Node.ELEMENT_NODE:
            printElement((Element)node);
            break;
          case Node.TEXT_NODE:
            printText((Text)node);
            break;
          case Node.COMMENT_NODE:
            printComment((Comment)node);
            break;
          case Node.CDATA_SECTION_NODE:
            printCDATA((CDATASection)node);
            break;
          case Node.ENTITY_REFERENCE_NODE:
            printEntityReference((EntityReference)node);
            break;
          case Node.PROCESSING_INSTRUCTION_NODE:
            printProcessingInstruction(
                (ProcessingInstruction)node);
            break;
          default:
        }
      }  protected void printElement(Element node) {
        Node child;
        Attr attr;
        System.out.print("<" + node.getNodeName());
        NamedNodeMap attrs = node.getAttributes();
        int count = attrs.getLength();
        for (int i = 0; i < count; i++) {
          attr = (Attr)(attrs.item(i));
          System.out.print(" " + attr.getName() + "=\"" + attr.getValue() +
                           "\"");
        }
        System.out.print(">");
        NodeList children = node.getChildNodes();
        count = children.getLength();
        for (int i = 0; i < count; i++) {
          child = children.item(i);
          displayTree(child);
        }
        System.out.print("</" + node.getNodeName() + ">");
      }
      protected void printText(CharacterData node) {
        System.out.print(node.getData());
      }  protected void printComment(Comment node) {
        System.out.print("<!--" + node.getData() + "-->");
      }  protected void printCDATA(CDATASection node) {
        System.out.print("<![CDATA[" + node.getData() + "]]>");
      }  protected void printEntityReference(EntityReference node) {
        System.out.print("&" + node.getNodeName() + ";");
      }  protected void printProcessingInstruction(ProcessingInstruction node) {
        System.out.print("<?" + node.getTarget() + " " + node.getData() + "?>");
      }}不管什么稳当全部搞顶哈哈哈
    我有没有希望拿分???
      

  4.   

    E:\java>java DOMTest a.xml
    Warning: validation was turned on but an org.xml.sax.ErrorHandler was
    set, which is probably not what is desired.  Parser will use a defaul
    ErrorHandler to print the first 10 errors.  Please call
    the 'setErrorHandler' method to fix this.
    Error: URI=file:/E:/java/a.xml Line=2: 组件类型“Root”未被声明。
    Error: URI=file:/E:/java/a.xml Line=2: 组件类型“Head”未被声明。
    Error: URI=file:/E:/java/a.xml Line=2: 组件类型“Time”未被声明。
    Error: URI=file:/E:/java/a.xml Line=2: 组件类型“Response”未被声明。
    Error: URI=file:/E:/java/a.xml Line=2: 组件类型“ID”未被声明。
    Error: URI=file:/E:/java/a.xml Line=2: 组件类型“Action”未被声明。
    Error: URI=file:/E:/java/a.xml Line=2: 属性“Type”未被声明为组件“Ac
    Error: URI=file:/E:/java/a.xml Line=2: 组件类型“RetCode”未被声明。
    Error: URI=file:/E:/java/a.xml Line=2: 组件类型“FlyDate”未被声明。
    Error: URI=file:/E:/java/a.xml Line=2: 组件类型“FromCity”未被声明。
    <Root>
    <Head>
    <Time>
    ................为什么前面输出那么一段?
      

  5.   

    你的xml本身就有问题的你没有DTD描述
    xml的开头又这么一行
    <!DOCTYPE LIBRARY system "library.dtd">
    使用来说明xml文档中的元素、属性、内容模式以及组成xml词汇表的实体
    当然dtd也并不就是只有上面的那一种方法那种叫做外部dtd子集
    还有一种叫做内部dtd子集
    区别就是内部dtd子集不需要独立的文件但是dtd被声明再xml文档的开头呵呵你还是找一本xml的书看看吧
    我这里只能说明又这么一回事,真正要弄明白还要看书
      

  6.   


    asdmonster(努力学习VC,讨回失去的信誉分) (
    兄台,非常感谢你的留言,但事实上我的给分是阴差阳错的给错了。
    我那200分就算是你给我留言的分吧
    你能不能开一个帖子给100分给gunnery(射手) 回答我问题的兄弟?
    因为我的可用分只有500多,不算多,如果不可以,也请留言给我,那我只有自己去开贴给分了
      

  7.   

    痛哭
    555555555555555555aaaaaaaaa...........