我正在尝试使用NSXMLParser来解析下面的数据:
<FORM ACTION="/prod/bwckgens.p_proc_term_date" METHOD="POST" onSubmit="return checkSubmit()">
<INPUT TYPE="hidden" NAME="p_calling_proc" VALUE="bwckschd.p_disp_dyn_sched">
<TABLE CLASS="dataentrytable" summary="This layout table is used for term selection."width="100%"><CAPTION class="captiontext">Search by Term: </CAPTION>
<TR>
<TD CLASS="dedefault"><LABEL for=term_input_id><SPAN class="fieldlabeltextinvisible">Term</SPAN></LABEL>
<SELECT NAME="p_term" SIZE="1" ID="term_input_id">
<OPTION VALUE="">None
<OPTION VALUE="201320">Spring 2013
<OPTION VALUE="201315">STAR/BGR: New Admits Fall 2012 (View only)
<OPTION VALUE="201310">Fall 2012 (View only)
<OPTION VALUE="201230">Summer 2012 (View only)
<OPTION VALUE="201220">Spring 2012 (View only)
<OPTION VALUE="201210">Fall 2011 (View only)
<OPTION VALUE="201130">Summer 2011 (View only)
<OPTION VALUE="201120">Spring 2011 (View only)
<OPTION VALUE="201110">Fall 2010 (View only)
<OPTION VALUE="201030">Summer 2010 (View only)
<OPTION VALUE="201020">Spring 2010 (View only)
<OPTION VALUE="201010">Fall 2009 (View only)
<OPTION VALUE="200930">Summer 2009 (View only)
<OPTION VALUE="200920">Spring 2009 (View only)
<OPTION VALUE="200910">Fall 2008 (View only)
<OPTION VALUE="200830">Summer 2008 (View only)
<OPTION VALUE="200820">Spring 2008 (View only)
</SELECT>
</TD>
</TR>
</TABLE>
<BR>
<BR>
<INPUT TYPE="submit" VALUE="Submit">
<INPUT TYPE="reset" VALUE="Reset">
</FORM>
我希望它将所有VALUE属性存储在字典中,或者使用相应的字符串存储,如下所示:
(201320, "Spring 2013")
(201315, "STAR/BGR: New Admits Fall 2012 (View only)")
(201310, "Fall 2012 (View only)")
....
我阅读了有关如何使用XML Parser的文档。我知道如何获取VALUE属性的值,但我不明白如何获取字符串的值,因为它们在元素OPTION关闭后出现。
任何人都可以通过制作XML树来向我展示如何构建所有内容,以及如何在每个OPTION属性之后提取String。
答案 0 :(得分:1)
你的结构错了。
<OPTION VALUE="200820">Spring 2008 (View only)
应该是
<OPTION VALUE="200820">Spring 2008 (View only)</OPTION>
结束</OPTION>
。
然后您可以使用http://obj-c.pl/parsowanie-xml-za-pomoca-nsxmlparser/
中的NSXMLParser示例 PS。 <INPUT>
错了。应该是<INPUT ... />
。