gpt4 book ai didi

java - XML SAX 解析未返回所需结果

转载 作者:行者123 更新时间:2023-11-30 04:05:23 25 4
gpt4 key购买 nike

我的客户提供了这样的 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>

这是我的解析代码:

public class DynamicXmlHandler extends DefaultHandler {

DynamicXMLgettersetter info = new DynamicXMLgettersetter();

boolean q_nameOn = false;
String q_nameValue = null;

boolean q_DescrptionOn = false;
String q_DescriptionValue = null;

boolean q_MainImgOn = false;
String q_MainImgValue = null;

boolean q_urldbOn = false;
String q_urldbValue = null;

boolean q_PriceOn = false;
String q_PriceValue = null;

boolean q_CatagoryOn = false;
String q_CatagoryValue = null;

boolean q_TmodeOn = false;
String q_TmodeValue = null;

boolean q_PmodeOn = false;
String q_PmodeValue = null;

// .................................................................

@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {

if (localName.equals("q_name")) {

q_nameOn = true;
}

if (localName.contentEquals("q_description")) {

q_DescrptionOn = true;

}

if (localName.contentEquals("q_urlmainimg")) {

q_MainImgOn = true;

}
if (localName.contentEquals("q_urldb")) {

q_urldbOn = true;

}
if (localName.contentEquals("q_priceindollar")) {

q_PriceOn = true;

}
if (localName.contentEquals("q_cattype")) {

q_CatagoryOn = true;

}
if (localName.contentEquals("q_thighscore")) {

q_TmodeOn = true;

}
if (localName.contentEquals("q_phighscore")) {

q_PmodeOn = true;

}

super.startElement(uri, localName, qName, attributes);
}

// ..................................................................

@Override
public void characters(char[] ch, int start, int length)
throws SAXException {

if (q_nameOn == true) {

q_nameValue = new String(ch, start, length);

}

if (q_DescrptionOn == true) {

q_DescriptionValue = new String(ch, start, length);

}

if (q_MainImgOn == true) {

q_MainImgValue = new String(ch, start, length);

}
if (q_urldbOn == true) {

q_urldbValue = new String(ch, start, length);

}
if (q_PriceOn == true) {

q_PriceValue = new String(ch, start, length);

}
if (q_CatagoryOn == true) {

q_CatagoryValue = new String(ch, start, length);

}
if (q_TmodeOn == true) {

q_TmodeValue = new String(ch, start, length);

}
if (q_PmodeOn == true) {

q_PmodeValue = new String(ch, start, length);

}

super.characters(ch, start, length);
}

// ..................................................................

@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {

if (localName.equalsIgnoreCase("q_name")) {

q_nameOn = false;
info.setqname(q_nameValue);
}

if (localName.equalsIgnoreCase("q_description")) {

q_DescrptionOn = false;
info.setdescription(q_DescriptionValue);
}

if (localName.equalsIgnoreCase("q_urlmainimg")) {

q_MainImgOn = false;
info.seturlimage(q_MainImgValue);
}
if (localName.equalsIgnoreCase("q_urldb")) {

q_urldbOn = false;
info.seturldb(q_urldbValue);
}

if (localName.equalsIgnoreCase("q_priceindollar")) {

q_PriceOn = false;
info.setpriceindollar(q_PriceValue);
}

if (localName.equalsIgnoreCase("q_cattype")) {

q_CatagoryOn = false;
info.setcattype(q_CatagoryValue);
}

if (localName.equalsIgnoreCase("q_thighscore")) {

q_TmodeOn = false;
info.setthighscore(q_TmodeValue);
}

if (localName.equalsIgnoreCase("q_phighscore")) {

q_PmodeOn = false;
info.setphighscore(q_PmodeValue);
}


super.endElement(uri, localName, qName);
}

当我使用 SAX 解析器解析它时,所有内容都被正确返回。但是当我尝试解析 <q_thighscore> 时或 <q_phighscore> , 它只返回 mode=1mode=2 ,但是我想解析完整链接,问题出在哪里,我现在应该怎么办?

最佳答案

这两个实体有一个符号 - 一个“&” - 正在变成一个“& # 3 8 ;”所以你必须以不同的方式处理代码中的那些

关于java - XML SAX 解析未返回所需结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11761393/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com