zoukankan      html  css  js  c++  java
  • 解析XML

    1、解析String类型的XML字符串得到属性值

    String  resultXML = "<?xml version="1.0" encoding="UTF-8"?>

      <result>

         <message value="0">yongyoulogin|用友ESB测试人员|创建|失败|人员已存在,</message>

          ......

      /result>";

    (1)、得到message中value的值

      //解析XML串

      StringReader   sr  =   new StringReader(resultXML);

      InputSource    is  =   new InputSource(sr);

      DocumentBuilderFactory   factory =   DocumentBuilderFactory.newInstance();

      DocumentBuilder   builder=  factory.newDocumentBuilder();

      Document   doc =   builder.parse(is);

      org.w3c.dom.Element   root   =   doc.getDocumentElement();

      NodeList   nl  =   root.getChildNodes();

      Node   message =  nl.item(0);

      String  value  =  message.getAttributes().getNamedItem("value").getNodeValue();

    (2)、得到标签中间的值  

      String  text  =   message.gettextcontent();  (text="yongyoulogin|用友ESB测试人员|创建|失败|人员已存在,")

  • 相关阅读:
    Linux命令:ls
    Log4j:log4j.properties 配置解析
    PostgreSQL: WITH Queries (Common Table Expressions)
    Linux使用SecureCRT上传下载
    PostgreSQL 自动输入密码
    Linux命令:rmdir
    Linux命令:mkdir
    Linux命令:pwd
    Linux命令:cd
    正则表达式 
  • 原文地址:https://www.cnblogs.com/fengzhanfei/p/6136901.html
Copyright © 2011-2022 走看看