此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
楼主【boxnoodle】截止到2008-06-29 09:03:31的历史汇总数据(不包括此帖):
发帖数:21                 发帖分:630                
结贴数:16                 结贴分:375                
未结数:5                  未结分:255                
结贴率:76.19 %            结分率:59.52 %            
楼主加油

解决方案 »

  1.   

    你是不是文件编码不对...用记事本打开,然后另存看下.是否是UTF-8,或者如果是ANSI,就一定错了.如果你的类本身是UTF-8编码,一般不会有问题.不知道你是jdom,还是dom4j....
      

  2.   

    我的XML是从数据库中读取的一个字段值,不存在文件编码不对的情况
      

  3.   

    先取到对应节点的值,然后转码Dom4j为例子Node node=document.selectSingleNode("/Files/File/@Name");
    String text=node.getText();
    text=new String(text.getBytes("UTF-8"),"GBK");
      

  4.   

    用jdom来试试。
    <?xml version="1.0" encoding="UTF-8"?><Files Domain="odpsfile" Path="2008"><File FileTempPath="6c08a588-c245-11dc-958a-d1128874cdde.doc" Index="1" Name="卫生防疫.doc" Title="新建"/></Files>
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.IOException;
    import java.util.Iterator;
    import java.util.List;import org.jdom.Attribute;
    import org.jdom.Document;
    import org.jdom.Element;
    import org.jdom.JDOMException;
    import org.jdom.input.SAXBuilder;public class Test{
        
        public static void doSomething(String fileName){
            
            SAXBuilder saxBuilder = new SAXBuilder();        
            Document doc;
            try {
                doc = saxBuilder.build(new FileReader(fileName));
                Element rootElement = doc.getRootElement();
                List<Attribute>  list = rootElement.getChild("File").getAttributes();
                Iterator<Attribute> iterator = list.iterator();        
                 while (iterator.hasNext()) {                   
                     Attribute e = iterator.next();
                     System.out.println(e.getName() + " : " + e.getValue());    
                }            
            } catch (FileNotFoundException e1) {
                e1.printStackTrace();
            } catch (JDOMException e1) {
                e1.printStackTrace();
            } catch (IOException e1) {
                e1.printStackTrace();
            }      
        }
        
        public static void main(String[] agrs) throws Exception {
            doSomething("C:/test.xml");
        }
    }
    [code=BatchFile]
    FileTempPath : 6c08a588-c245-11dc-958a-d1128874cdde.doc
    Index : 1
    Name : 卫生防疫.doc
    Title : 新建
    [/code]
      

  5.   

    按照五楼的还是不行,错误org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0x11) was found in the value of attribute "Name" and element is "File".再按六楼的看行不行