用的toString()方法。直接转成字符串就ok啦!

解决方案 »

  1.   

    知道可以用toString。的方法我的意思是。我想把<Step name="testfile">
                <Request>
                    <MessageHeader>
                        <Method encoding="text">GET</Method>
                        <URI encoding="text">${path}classifieds/index.cgi</URI>
                        <Version encoding="text">HTTP/1.0</Version>
                    </MessageHeader>
                </Request>
                <Response>
                    <SetVariable name="ResponseCode" type="string">
                        <Description>The HTTP Response Code</Description>
                        <Source source="status-line">^.*\s(\d\d\d)\s</Source>
                    </SetVariable>
                    <SetVariable name="body404" type="string">
                        <Description>See if we got a custom error page, incorrectly implemented with a return code of 200</Description>
                        <Source source="message-body">(404.*[Nn]ot [Ff]ound)</Source>
                    </SetVariable>
                    <SetVariable name="redir302" type="string">
                        <Description>Check to see if we are being redirected to another page</Description>
                        <Source source="message-header">^Location: (.*)$</Source>
                    </SetVariable>
                    <SetVariable name="bodymatch" type="string">
                        <Source source="message-body"></Source>
                    </SetVariable>            </Response>
                <TestCriteria type="SUCCESS">
                    <Compare variable="${ResponseCode}" test="equals">
                        <Value>200</Value>
                    </Compare>
                </TestCriteria>
                <TestCriteria type="FAILURE">
                    <Compare variable="${ResponseCode}" test="equals">
                        <Value>404</Value>
                    </Compare>
                </TestCriteria>
                <TestCriteria type="FAILURE">
                    <ErrorMessage>This test was redirected to ${redir302}. The program that generated this test does not know how to handle 302 responses. Unfortunately, they are quite common in the Microsoft arena. Please update the generator, and rebuild these tests</ErrorMessage>
                    <Compare variable="${ResponseCode}" test="equals">
                        <Value>302</Value>
                    </Compare>
                </TestCriteria>
                <TestCriteria type="FAILURE">
                    <ErrorMessage>This message indicates a failure to properly execute the test, or an unhandled HTTP response. Please investigate further, and modify this test before re-executing it. The server returned ${ResponseCode}</ErrorMessage>
                    <Compare variable="${ResponseCode}" test="notequals">
                        <Value>200</Value>
                    </Compare>
                </TestCriteria>        </Step>
    不经过解析。直接以toString的形式存到一个字符串上
    需要如何做呢??请求高人写一个简单的DEMO
    急用
      

  2.   


    import java.io.File;
    import java.io.IOException;
    import java.io.OutputStreamWriter;
    import java.io.Writer;// JAXP
    import javax.xml.parsers.FactoryConfigurationError;
    import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.DocumentBuilder;// DOM
    import org.w3c.dom.Document;
    import org.w3c.dom.DocumentType;
    import org.w3c.dom.NamedNodeMap;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;public class TestDOMParsing {    public static void main(String[] args) {
            try {
                if (args.length != 1) {
                    System.err.println ("Usage: java TestDOMParsing [filename]");
                    System.exit (1);
                }            // Get Document Builder Factory
                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();            // Leave off validation, and turn off namespaces
                factory.setValidating(false);
                factory.setNamespaceAware(false);            DocumentBuilder builder = factory.newDocumentBuilder();
                Document doc = builder.parse(new File(args[0]));            // Print the document from the DOM tree and
                //   feed it an initial indentation of nothing
                printNode(doc, "");        } catch (ParserConfigurationException e) {
                System.out.println("The underlying parser does not support the requested features.");
            } catch (FactoryConfigurationError e) {
                System.out.println("Error occurred obtaining Document Builder Factory.");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }    private static void printNode(Node node, String indent)  {
            switch (node.getNodeType()) {
                case Node.DOCUMENT_NODE:
                    System.out.println("<xml version=\"1.0\">\n");
                    // recurse on each child
                    NodeList nodes = node.getChildNodes();
                    if (nodes != null) {
                        for (int i=0; i<nodes.getLength(); i++) {
                            printNode(nodes.item(i), "");
                        }
                    }
                    break;
                    
                case Node.ELEMENT_NODE:
                    String name = node.getNodeName();
                    System.out.print(indent + "<" + name);
                    NamedNodeMap attributes = node.getAttributes();
                    for (int i=0; i<attributes.getLength(); i++) {
                        Node current = attributes.item(i);
                        System.out.print(" " + current.getNodeName() +
                                         "=\"" + current.getNodeValue() +
                                         "\"");
                    }
                    System.out.print(">");
                    
                    // recurse on each child
                    NodeList children = node.getChildNodes();
                    if (children != null) {
                        for (int i=0; i<children.getLength(); i++) {
                            printNode(children.item(i), indent + "  ");
                        }
                    }
                    
                    System.out.print("</" + name + ">");
                    break;            case Node.TEXT_NODE:
                    System.out.print(node.getNodeValue());
                    break;
            }
        }}这里有一个DEMO
      

  3.   

    不解析的话,直接用InputStream读取就可以了
      

  4.   

    读的时候判断位置然后到了你要的位置并累加
    到结束 调用Jdom iostream 取出
      

  5.   


    知道可以用InputStream
    但是因为xml文件太多。
    而且前面要解析。后面要输出。用InpuStream增加的复杂度