用css 可以解决,就是html 里面用的那个css
也能插入到xml中,跟在html里的用法差不多。
例子如下:
//---------------Books-css.xml------------------<?xml version="1.0" encoding="gb2312" standalone="no"?>
<?xml-stylesheet type="text/css" href="Books.css"?>
<!DOCTYPE BOOKS SYSTEM "Books.dtd">  
<Books>
    <Book Color="blue">
<Name>语文第一册</Name>
<Author>eagle</Author>
        <Price>19.6</Price>
    </Book>
</Books>//-----------------------Books.css------------------
Author
{
DISPLAY: block; COLOR: blue;
}Name
{
FONT-SIZE: 20pt; BACKGROUND: #ffffff; CURSOR: hand
}
Price
{
DISPLAY: block; COLOR: blue;
}

解决方案 »

  1.   


    public void formatXMLFile(String filename) {
    try {
    SAXReader saxReader = new SAXReader();
    Document document = saxReader.read(new File(filename));
    XMLWriter writer = null;
    // 格式化输出,类型IE浏览一样
    OutputFormat format = OutputFormat.createPrettyPrint();
    // 指定XML编码
    format.setEncoding("GB2312");
    writer = new XMLWriter(new FileWriter(new File(filename)), format);
    writer.write(document);
    writer.close(); } catch (Exception e) {
    e.printStackTrace();
    } }上面是dom4j写XML的时候格式化
      

  2.   

    如果不是dom4j写的呢?有没有办法呢? 我的代码都写完了,难道一定要为这个问题,全部重写么?
      

  3.   


    使用这个都需要导入一些额外的jar包么,一些东西,系统库里找不到啊
      

  4.   


    import org.dom4j.Document;
    import org.dom4j.io.OutputFormat;
    import org.dom4j.io.SAXReader;
    import org.dom4j.io.XMLWriter;只要导入dom4j.jar就行了