新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论DOM, SAX, XPath等。
    [返回] 计算机科学论坛XML.ORG.CN讨论区 - XML技术『 DOM/SAX/XPath 』 → Element的toString方法不能解析出子节点的内容 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 2532 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: Element的toString方法不能解析出子节点的内容 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     xiaoshuyu 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:1
      积分:57
      门派:XML.ORG.CN
      注册:2005/4/29

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给xiaoshuyu发送一个短消息 把xiaoshuyu加入好友 查看xiaoshuyu的个人资料 搜索xiaoshuyu在『 DOM/SAX/XPath 』的所有贴子 引用回复这个贴子 回复这个贴子 查看xiaoshuyu的博客楼主
    发贴心情 Element的toString方法不能解析出子节点的内容

    我把Apache AXIS的jar包和xerces.jar加到classPath之后,Element的toString 方法就不能解析出内容来了,只得到了一个根节点的名字。
    <学生花名册>
    <学生 性别 = "男">
    </学生>
    </学生花名册>

    这个Element,如果我调用它的toString方法,得到的是[学生花名册:null],而我想得到的是<学生花名册><学生 性别 = "男"></学生></学生花名册> 。帮个忙,急用,谢谢!


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2005/4/29 10:09:00
     
     xiaoshuyu 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:1
      积分:57
      门派:XML.ORG.CN
      注册:2005/4/29

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给xiaoshuyu发送一个短消息 把xiaoshuyu加入好友 查看xiaoshuyu的个人资料 搜索xiaoshuyu在『 DOM/SAX/XPath 』的所有贴子 引用回复这个贴子 回复这个贴子 查看xiaoshuyu的博客2
    发贴心情 


    import java.io.*;
    import java.util.*;
    import javax.xml.parsers.*;

    import org.apache.crimson.tree.XmlDocument;//
    import org.xml.sax.*;
    import org.w3c.dom.*;
    public class Test{
     
     public Test(){
      
     }
     public InputSource parseXml(String inXml){
      if (inXml == null) {
      throw new IllegalArgumentException();
      }
      try {
      return  new InputSource(new StringReader(inXml));
      } catch (Exception e) {
      throw new RuntimeException(e.getMessage());
      }

     }
     
     public static void main(String[] args){
      
      Test tempTest = new Test();
      StringBuffer xmlString = new StringBuffer();
         xmlString.append("<?xml version=\"1.0\"?>\n");
         xmlString.append("<userAuth>\n");
         xmlString.append("    <token>").append("704e68fb6ccfc3e3f1b6d7ac41291c62").append("</token>\n");
         xmlString.append("    <username>").append("2509409").append("</username>\n");
         xmlString.append("    <serviceid>").append("001").append("</serviceid>\n");
         xmlString.append("    <contentid>").append("4").append("</contentid>\n");
         xmlString.append("    <contentname>").append("test").append("</contentname>\n");
         xmlString.append("    <price>").append("53").append("</price>\n");
         xmlString.append("    <police>").append("1").append("</police>\n");
         xmlString.append("    <ip>").append("192.168.0.2").append("</ip>\n");
         xmlString.append("    <spid>").append("sp001").append("</spid>\n");
            xmlString.append("</userAuth>");
      
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      DocumentBuilder db = null;
      try {
       db = dbf.newDocumentBuilder();
      } catch (ParserConfigurationException pce) {
       System.err.println(pce); //&sup3;&ouml;&Ograve;ì&sup3;&pound;&Ecirc;±&Ecirc;&auml;&sup3;&ouml;&Ograve;ì&sup3;&pound;&ETH;&Aring;&Iuml;&cent;&pound;&not;&Egrave;&raquo;&ordm;ó&Iacute;&Euml;&sup3;&ouml;&pound;&not;&Iuml;&Acirc;&Iacute;&not;
       System.exit(1);
      }
      
      Document doc = null;
      try {
       doc = db.parse(tempTest.parseXml(xmlString.toString()));
      } catch (Exception dom) {
       System.err.println(dom.getMessage());
       System.exit(1);
      }
      Element root = doc.getDocumentElement();
      System.out.println(root.toString());

     }

     }
     
     
    }

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2005/4/30 11:52:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 DOM/SAX/XPath 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2025/12/24 10:53:08

    本主题贴数2,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    62.500ms