JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java & XML、Web Service  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 可以取到xml的name,取不到value.大傢幫忙看看??
擺渡人

來自:北灣村



發文: 32
積分: 0
於 2004-08-11 09:00 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
XML格式代馬:
1
2
3
4
5
.............
<answer>
   <ResultCode>aa</ResultCode>
   <Result>bb</Result>
</answer>

我用下面的去取這個(上麵是訪問一個servlet頁麵的返迴值.)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
............................................
       Writer out = new OutputStreamWriter( socket.getOutputStream(), "GB2312"); 
       out.write("GET /CPModule/cppushservlet?CP_Num=CP003&CP_Password=fuzhoumhnet&SP_ICP=8566&SP_SUB=123&Service_Comd=A&Service_Type=7&Dst_MSISDN=13358253175&Service_Version=1&SMS_Content=短信内容(GBK编码)&SMS_Fmt=15&Fee_MSISDN=13358253175&Seq_Num=4567 HTTP/1.1\r\n"); 
       out.write("Host: " + TARGET_HTTPS_SERVER + ":" +  TARGET_HTTPS_PORT + "\r\n"); 
 
       out.write("\r\n"); 
       out.flush(); 
      // BufferedReader in = new BufferedReader( new InputStreamReader(socket.getInputStream(), "GB2312")); 
   
      // while ((line = in.readLine()) != null) { 
    //    System.out.println("line=="+line); 
     //  } 
 
             InputStream is = socket.getInputStream();
             DocumentBuilderFactory df = DocumentBuilderFactory.newInstance();
             DocumentBuilder db = df.newDocumentBuilder();
             Document doc = db.parse(is);
       System.out.println("parse successfull");
 
         Element root = doc.getDocumentElement();
               NodeList nl = root.getChildNodes();
         System.out.println("length=="+nl.getLength());
               Node tempNode = null;
          for(int i=0;i<nl.getLength();i++)
                {
                        tempNode = nl.item(i);
                        nodeName = tempNode.getNodeName();
                        nodeValue = tempNode.getNodeValue();
                        System.out.println("nodeName=="+nodeName);
            System.out.println("nodeValue=="+nodeValue);
 
               }
............................................

上面是個main.執行結果如下:
parse successfull
length==2
nodeName==ResultCode
nodeValue==null (怎麼這個為null值)
nodeName==Result
nodeValue==null (怎麼這個為null值)

請問那裡錯了.............????


擺渡人 edited on 2004-08-17 12:01
reply to postreply to post
記憶太長~
心事太重~
夢想太多~
作者 Re:可以取到xml的name,取不到value.大傢幫忙看看?? [Re:擺渡人]
allex





發文: 36
積分: 1
於 2004-08-16 18:05 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
記得是要用
1
2
String name = node.getNodeName();
String value = node.getFirstChild().getNodeValue();


節點的值是其第一個child的值
而非節點本身的值


reply to postreply to post
作者 Re:可以取到xml的name,取不到value.大傢幫忙看看?? [Re:擺渡人]
teresayu





發文: 5
積分: 0
於 2007-10-17 23:51 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我也有類似的問題

我的xml內容如下:
1
<a requestId="1" resultCode="00000"/>


將String xmlSrc設成上述xml內容
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
           xmlSrc = "<?xml version=\"1.0\">\n" + 
                      "<!DOCTYPE a PUBLIC \"//\" \"a.dtd\">\n" + 
                      xmlSrc;
 
           // Get Document Builder Factory
           DocumentBuilderFactory factory = 
                   DocumentBuilderFactory.newInstance();
 
           // Turn on validation, and turn off namespaces
           factory.setValidating(true);
           factory.setNamespaceAware(false);
 
           // Obtain a document builder object
           DocumentBuilder builder = factory.newDocumentBuilder();
           
           // Parse the document
           Document doc = builder.parse(new InputSource(new StringReader(xmlSrc)));
隨即出現
org.xml.sax.SAXParseException: A pseudo attribute name is expected. 
  at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)


請問大大們要如何解這樣的問題
勞煩了


teresayu edited on 2007-10-17 23:56
reply to postreply to post
» JWorld@TW »  Java & XML、Web Service

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8