簡體   English   中英

xml SAX解析未返回所需結果

[英]xml SAX parsing doesnt returned the desired result

我的客戶提供了這樣的xml:

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

但是當我使用SAX解析器解析它時,一切都正確返回,但是當我嘗試解析<q_thighscore><q_phighscore>它返回的只是mode=1mode=2 ,但我想解析完整鏈接,這是問題所在,我現在應該怎么辦?

您可能要使用sax默認處理程序。 看看是否可行。 如果不是,則可能需要擴展默認的Handler並重寫此方法的行為以正確存儲值。 其中myURLString是您在擴展類中定義的變量。 然后可以在endElement方法中訪問此變量以進行采樣。 您可以在這里完全控制。

因此,一種方法是擴展org.xml.sax.helpers.DefaultHandler;。

並覆蓋如下

   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解析器,就可以了:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM