你这个明明就是welformed的xml嘛,可以解析的啊

解决方案 »

  1.   

    你的意思是把这部分插入另外一个完整的树的一个节点里面吗?
    那先用dom装载它,然后createNode的好像就可以了
      

  2.   

    這些都是文件不是在內存裡的節點,如果可以把它拆成一個個節點當然問題就可以解決,但是要把上面的文件一次生成節點只能用text了,也就是整個文件都變成了一個text,在文件裡的結點就不能解析出來了
    要解析的文件是不完全符合xml格式的
      

  3.   

    我刚刚遇到过这种问题,我是通过把<,>编码的方法“避”过去的楼上的能不能把你们的方法说清楚些?怎么用Text啊?
      

  4.   

    把<,>编码?那就不能成為xml的節點了
     Text createTextNode(String data) 
              Creates a Text node given the specified string. 
    你的意思是把这部分插入另外一个完整的树的一个节点里面吗?
    ->差不多
    那先用dom装载它,然后createNode的好像就可以了
    ->好像不可以,我不懂如何把它作為Node,實作一下你看可不以可以,可以的話就好了
      

  5.   

    <man>
    <name>
    aaaaaaa
    </name>
    </man>
    怎么就不能解析啊?
      

  6.   

    因為可能會出現
    <man>
    <name>
    aaaaaaa
    </name>
    </man>
    <man>
    <name>
    bbbbb
    </name>
    </man>
    懂的人給點提示吧
      

  7.   

    javascript:
    a=new ActiveX.....(Document...);
    a.loadXML("<ssss>s.....</ssss>");
    a...
      

  8.   

    try XMLFragment:
    public static DocumentFragment parseXml(Document doc, String fragment) {
            // Wrap the fragment in an arbitrary element
            fragment = "<fragment>"+fragment+"</fragment>";
            try {
                // Create a DOM builder and parse the fragment
                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                Document d = factory.newDocumentBuilder().parse(
                    new InputSource(new StringReader(fragment)));
        
                // Import the nodes of the new document into doc so that they
                // will be compatible with doc
                Node node = doc.importNode(d.getDocumentElement(), true);
        
                // Create the document fragment node to hold the new nodes
                DocumentFragment docfrag = doc.createDocumentFragment();
        
                // Move the nodes into the fragment
                while (node.hasChildNodes()) {
                    docfrag.appendChild(node.removeChild(node.getFirstChild()));
                }
        
                // Return the fragment
                return docfrag;
            } catch (SAXException e) {
                // A parsing error occurred; the xml input is not valid
            } catch (ParserConfigurationException e) {
            } catch (IOException e) {
            }
            return null;
        }
      

  9.   

    可以顺利解析呀!
    /*
     * Created on 2004-9-21
     *
     * To change the template for this generated file go to
     * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
     */
    package weich;import org.jdom.input.SAXBuilder;
    import org.jdom.Document;
    import org.jdom.JDOMException;
    import org.jdom.Element;import java.io.FileInputStream;
    import java.io.IOException;
    /**
     * @author Administrator
     *
     * To change the template for this generated type comment go to
     * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
     */
    public class ParseXml { public static void main(String[] args) {
    SAXBuilder sb = new SAXBuilder();
    Document doc = null;
    try{
    doc = sb.build(new FileInputStream("parse.xml"));
    }catch(JDOMException jdome){
    jdome.printStackTrace();
    }catch(IOException ioe){
    ioe.printStackTrace();
    }
    Element root = doc.getRootElement();
    System.out.println(root.getName());
    Element EleName= root.getChild("name");
    System.out.println("EleName:"+EleName.getName()+"EleName.getText:"+root.getChildTextTrim("name"));
    }
    }