在JDOM里,我用XMLOutputter类的output方法,把DOCUMNET对象输出到字符串,为什么St会有<xml version=..>开头,如何去除ByteArrayOutputStream b = new ByteArrayOutputStream()
xmloutputter.output(document,b);
b.toString(); 就有<xml version=..>开头,document对象里一定要包含<xml version=..>?
如何去除在output()时谢谢

解决方案 »

  1.   

    xml标准。
    你可以最后用replaceAll()从字符串里删除掉
      

  2.   

    主要是<xml version=..>后面还会有个换行符,
    replaceAll()要怎么写,才能把<xml version=..>和换行符也去除,谢谢
      

  3.   

    str = str.replaceAll("<?xml version=\"1.0\" encoding=\"UTF-8"?>\");
    就是删除不了,请哪位大侠出手
      

  4.   

    为什么不要xml行??
    删掉就不是xml文件了...
      

  5.   

    我只想传输XML格式的报文,不用“<?xml version=\"1.0\" encoding=\"UTF-8"?>”
    现在问题是replaceAll方法,为什么下面语句删除不了呢
    str = str.replaceAll(" <?xml version=\"1.0\" encoding=\"UTF-8\"?>"); 谢谢
      

  6.   

    public void doDeleteFromXMLFile(String area, String catalog, String name, 
                                        String desc, String username) { 
            String xmlPath = "storyboard/XML/db.xml"; 
            XMLOutputter outputter = null; 
            
            SAXBuilder saxBuilder = new SAXBuilder(false); 
            try { 
                Document doc = saxBuilder.build(xmlPath); 
                Element goodsinfo = doc.getRootElement(); 
                List goods = goodsinfo.getChildren("goods"); 
                for (int i = 1; i < goods.size() + 1; i++) { 
                    Element current = (Element) goods.get(i - 1);                 String _area = current.getChild("area").getText().toString(); 
                    String _catalog = current.getChild("catalog").getText(). 
                                      toString(); 
                    String _name = current.getChild("name").getText().toString(); 
                    String _description = current.getChild("description").getText(). 
                                          toString(); 
                    String _username = current.getChild("username").getText(). 
                                      toString(); 
                    if (_area.equals(area) && _catalog.equals(catalog) && 
                        _name.equals(name) && _description.equals(desc) && 
                            _username.equals(username))  {                     current.getParentElement().removeContent(current); 
                        System.out.println("doDeleteFromXMLFile() is called."); 
                        break; 
                    } 
                } 
                //System.out.println("checked1"); 
                Format format = Format.getCompactFormat(); 
                format.setIndent("  "); 
                format.setEncoding("UTF-8");             outputter = new XMLOutputter(format); 
                FileWriter writer = new FileWriter(xmlPath); 
                outputter.output(goodsinfo, writer); 
                //Writer.flush(); 
                writer.close(); 
                //System.out.println("checked2");         } catch (JDOMException e) { 
                e.printStackTrace(); 
            } catch (IOException e) { 
                e.printStackTrace(); 
            } 
        } 
      

  7.   

    这个一般都是xml的第一行 实在不行 判断一下 然后忽略这一行不就可以了吗?