试卷xml,
<section name="单选题(本大题共33小题,共0.0分)">
<section name="一、选择题(本大题共8小题,共40分)" score="40" ></span>
因为试卷的选择题的类型并没有统一,类型信息包含在name的字符串中,而xml格式是其他人定义的,不能修改,所以要使用xpath进行模糊查找。
contains是一个字符串查找函数
语法是:fn:contains(string1,string2),表示如果 string1 包含 string2,则返回 true,否则返回 false。
例如:contains('XML','XM'),结果:true。
<paper name="地理测试01" subject="Geography" id="test01" >
<section name="单选题(本大题共33小题,共0.0分)">
<questions>
<question id="test01_01" type="select">
<text format="html">读下图,若从A点沿经线向B方向发射一颗射程为4000千米的导弹,则关于导弹落点的叙述,正确的是__<Picread id="Pic1_1"></Picread></text>
<select multiple="false">
<option value="A">导弹将落在北半球.西半球</option>
<option value="B">导弹落点所在地一年中有两次太阳直射机会</option>
<option value="C">导弹落在低纬度地区</option>
<option value="D">导弹落在B点的东南方向.A点的东北方向</option>
</select>
</question>
</questions>
</section>
</paper>
</pre><pre name="code" class="html" style="font-size: 0.9em;">php代码如下:
</pre><p></p><p><pre name="code" class="html" style="font-size: 0.9em;">$selectSections=$shortSections=$paper_content->xpath("/paper//section[contains(@name,'选择') or contains(@name,'单选')]");
//dd($selectSections);
$selectSection=$selectSections[0];
dd($selectSection);
显示如下: