简体   繁体   中英

xml SAX parsing doesnt returned the desired result

I have an xml provided by my client like this:

<?xml version='1.0' encoding='UTF-8' ?><quizzes updatetimestamp='2012-08-01 06:24'><quiz q_id='1'>
<q_name>Airplane!</q_name >
<q_appleid>com.patelware.moviesquiz.free</q_appleid>
<q_description>"Roger, Roger"</q_description>
<q_urlicon>http://www.inall3.com/king/icons/airplane_icon.png</q_urlicon>
<q_urlmainimg>http://www.inall3.com/king/icons/airplane_main.png</q_urlmainimg>
<q_urldb>http://www.inall3.com/king/dbs/airplane.xml</q_urldb>
<q_timesofupload>2011-05-01 00:00:00</q_timesofupload>
<q_priceindollar>0.00</q_priceindollar>

<q_cattype>Comedy</q_cattype>
<q_thighscore>http://www.inall3.com/hs/highscoreairplane.php?action=gethighscores&amp;mode=1</q_thighscore>
<q_phighscore>http://www.inall3.com/hs/highscoreairplane.php?action=gethighscores&amp;mode=2</q_phighscore>
</quiz>

but when I parse it using SAX parser everything is returned correctly but when I try to parse <q_thighscore> or <q_phighscore> its returning just mode=1 and mode=2 , but I want full link to be parsed, where is the problem and what should I do now?

You might want to use sax default Handler. See if it works. If not might need to extend default Handler and override behavior of this method to store the value correctly. Where myURLString is a variable you define in you extended class. This variable can then be accessed in endElement method for eample. you have total control over this here.

So one way is to extend org.xml.sax.helpers.DefaultHandler;

and override as below

   protected String myValueString;


   @Override
   public void characters(char[] ch, int start, int length) throws SAXException
   {
    super.characters(ch, start, length);  // deal with escape values here.
            myValueString = ...

    }

then inside   endElement(){


   check if matches your type and if so use myValueString;

我已经解决了它,我只用了Pull解析器而不是SAX解析器,就可以了:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM