2011-08-11 1 views
0

私はSaxParsingを使用してWebサービスからの応答を解析しています。ここでは、私が得るxmlファイルを提供していますSaxparsingの問題

<HelpDesk xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
<entry> 
<id>1</id> 
<parent>0</parent> 
<name> 
<![CDATA[ Equipment Tab ]]> 
</name> 
<description> 
<![CDATA[ ]]> 
</description> 
<content> 
<![CDATA[ 
There are several ways equipment can be added to a booking. Equipment can be added through the tree view of the inventory. It can be added by searching the product code or description. Once equipment is selected for the booking adjustments can be made to&nbsp;the quantity, price, and discount&nbsp;for each line of equipment. Specific pricing models on a per line basis can be created. Discounts can be applied to the entire booking. This will not conflict with any line item discounts. If a discount on the line already exists the overall booking discount will skip the line amount and apply to other applicable lines. Once pricing is complete taxes can be applied as required. Multiple tax rates can be applied by clicking on a tax box. Operator discount authorizations are controlled by the individual operator and not at the group level. 
]]> 
</content> 
<rating>80</rating> 
<votes>36</votes> 
<views>169</views> 
<private>0</private> 
<status/> 
</entry> 
</HelpDesk> 

問題コンテンツタグには完全な内容がありません。 は、誰もが

おかげ

答えて

1

があなたのXMLハンドラの文字方法bufが文字列ビルダーです

public void characters (char ch[], int start, int length) { 
    if (buf!=null) { 
     for (int i=start; i<start+length; i++) { 
      buf.append(ch[i]); 
     } 
    } 
} 

でこれを使って、このXMLを解析するためのコードを与えることができます。

1

あなたがのstartElement()メソッドでのStringBufferをinitilize、あなたが文字になっている文字列を追加しなければならない()文字列バッファ

public void startElement(String namespaceURI, String localName, 
      String qName, Attributes atts) throws SAXException { 
     if(localName.equals("content")){ 
      sb= new StringBuffer(); 

    } 
} 

public void characters(char ch[], int start, int length) { 
    if(tagName.equals("content")){ 
     sb.append(new String(ch, start, length)); 
     //use this string buffer where you want 
} 
にする方法
関連する問題