开发者

Saxparsing problem

I am using SaxParsing to parse the response from webservice. Here i am giving the xml file I am getting

<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>

Problem is i am not getting the full contents in content tag. Can anybody give the code to parse this xml

T开发者_如何学JAVAhanks


Use this in the character method of your xml handler

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

Where buf is a string builder.


You should initilize the StringBuffer at the startElement() method and append the string you are getting at the characters() method to the String buffer

 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
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜