xml结构如下<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" id="attr">
<SOAP-ENV:Body>
<m:editBroadbandAccountRequest
xmlns:m="http://uac.bossuac.com.cn/">
<systemId>{SYSTEMID}</systemId>
<BroadbandAccount_2>
<userId>{USERID}</userId>
<userPassword>{USERPASSWORD}</userPassword>
<plcRate>{PLC_RATE}</plcRate>
<plcBurst>{PLC_BURST}</plcBurst>
<mtrRate>{MTR_RATE}</mtrRate>
<mtrBurst>{MTR_BURST}</mtrBurst>
<framedIpAddress>{FRAMEDIPADDRESS}</framedIpAddress>
<flowNo>{FLOWNO}</flowNo>
<userGroup>{USERGROUP}</userGroup>
<sendTime>{SENDTIME}</sendTime>
<userType>{USERTYPE}</userType>
<remainTime>{REMAINTIME}</remainTime>
<maxOnLineTime>{MAXONLINETIME}</maxOnLineTime>
<idleTimeout>{IDLETIMEOUT}</idleTimeout>
<web_Url>{WEB_URL}</web_Url>
<filter>{FILTER}</filter>
<bindMode NUM="N">{BINDMODE}</bindMode>
<vLan>{VLAN}</vLan>
<port>{PORT}</port>
<slotNo>{SLOTNO}</slotNo>
<xpi>{XPI}</xpi>
<xci>{XCI}</xci>
<macAddress>{MACADDRESS}</macAddress>
<zone>{ZONE}</zone>
<portLimit>{PORTLIMIT}</portLimit>
<profile_name>{PROFILE_NAME}</profile_name>
<validTime>{VALIDTIME}</validTime>
<frame_Pool>{FRAME_POOL}</frame_Pool>
<userName>{USERNAME}</userName>
<userTel>{USERTEL}</userTel>
<iDCardCode>{IDCARDCODE}</iDCardCode>
<userAddress>{USERADDRESS}</userAddress>
<emailAddress>{EMAILADDRESS}</emailAddress>
<prePaid>{PREPAID}</prePaid>
<measure>{MEASURE}</measure>
<useGroup>{USERGROUP}</useGroup>
<bindflag>{BINDFLAG}</bindflag>
<extString1>{PORT}</extString1>
<extString2>{PORTLIMIT}</extString2>
<extString3>{PREPAID}</extString3>
<extString4>{PROFILE_NAME}</extString4>
<extString5>{REMAINTIME}</extString5>
<extString6>{SENDTIME}</extString6>
<extString7>{SLOTNO}</extString7>
<extString8>{USERGROUP}</extString8>
<extString9>{USERADDRESS}</extString9>
<extString10>{USERGROUP}</extString10>
</BroadbandAccount_2>
</m:editBroadbandAccountRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
java代码如下:取根节点的所有属性                Element root = document.getRootElement();
int attrCount = root.attributeCount();
                System.out.println("attrCount:::"+attrCount);
for (int i=0; i<attrCount; i++){
Attribute attr = root.attribute(i);
System.out.println(attr.getName());
}这段代码是用来取xml文档根节点的所有属性,但是现在打印出来的结果是:
attrCount:::1
id也就是说像根节点的
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"这些属性都没取到,请问我如何才能取到这些属性呢?谢谢了。

解决方案 »

  1.   

     for (int i=0; i<attrCount; i++){
                Attribute attr = root.attribute(i);
                System.out.println(attr.getName());
            }你这里只有getName 啊 。 要getAttribute()吧 用获取属性那个方法。
      

  2.   

        Element root = document.getRootElement();
            for (Object o : root.declaredNamespaces()) {
                Namespace ns = (Namespace) o;
                System.out.println(ns.getName() + "=\"" + ns.getURI() + "\"");
            }
      

  3.   

    Element root = document.getRootElement();
      for (Object o : root.declaredNamespaces()) {
      Namespace ns = (Namespace) o;
      System.out.println("xmlns:" + ns.getPrefix() + "=\"" + ns.getURI() + "\"");
      }
      

  4.   

    declaredNamespaces()要dom4j才有的吧
      

  5.   


    请问四楼的兄弟,
     System.out.println("xmlns:" + ns.getPrefix() + "=\"" + ns.getURI() + "\""……
    我如何得到xmlns,而不是直接加上。
      

  6.   

    取不了吧。
    xmlns个是xml命名空间属性,是内置属性。看看,是讲html的,不过xml也差不多
    http://www.w3school.com.cn/tags/tag_prop_xmlns.asp
      

  7.   

    属性的取得方法  例如
    e.valueOf("@" + 属性名称)