从iphone中的数组中的xml文件中获取零对象 [英] getting zero objects from the xml file in the array in iphone

查看:143
本文介绍了从iphone中的数组中的xml文件中获取零对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我正在尝试将xpathQuery用于以下xml数据。

Hi all i am trying to use xpathQuery for the below xml data.

我的xml文件以assessmentItem开头。在assessmentItem之前甚至没有单个字符

My xml file starts with assessmentItem. There is not even single character before assessmentItem

<assessmentItem adaptive="false" identifier="wordsearch" timeDependent="false" title="Word Search" xsi:schemaLocation="http://www.imsglobal.org/xsd/imsqti_v2p1 
http://www.imsglobal.org/xsd/imsqti_v2p1.xsd" 
xmlns="http://www.imsglobal.org/xsd/imsqti_v2p1"   
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">



<itemBody>


<div id="heading">
  <p><![CDATA[<TextFlow columnCount="inherit" columnGap="inherit" columnWidth="inherit" fontFamily="Verdana" fontSize="9" lineBreak="inherit" paddingBottom="inherit" paddingLeft="2" paddingRight="2" paddingTop="6" verticalAlign="inherit" whiteSpaceCollapse="preserve" xmlns="http://ns.adobe.com/textLayout/2008"><p><span>Word search</span></p></TextFlow>]]></p>
</div>
<div id="direction">
  <p><![CDATA[<TextFlow columnCount="inherit" columnGap="inherit" columnWidth="inherit" fontFamily="Verdana" fontSize="9" lineBreak="inherit" paddingBottom="inherit" paddingLeft="2" paddingRight="2" paddingTop="6" verticalAlign="inherit" whiteSpaceCollapse="preserve" xmlns="http://ns.adobe.com/textLayout/2008"><p><span>Find the words in the grid</span></p></TextFlow>]]></p>
</div>
<div id="mask">
  <p><![CDATA[Yes]]></p>
</div>
<div id="layout">
  <p><![CDATA[13*13]]></p>
</div>
<div id="numOfGuesses">
  <p><![CDATA[10]]></p>
</div>
<matchInteraction maxAssociations="2" responseIdentifier="RESPONSE" shuffle="true">
  <simpleMatchSet>
    <simpleAssociableChoice identifier="W_1" matchMax="1">
      <p><![CDATA[harsha]]></p>
    </simpleAssociableChoice>
    <simpleAssociableChoice identifier="W_2" matchMax="1">
      <p><![CDATA[dinakar]]></p>
    </simpleAssociableChoice>
    <simpleAssociableChoice identifier="W_3" matchMax="1">
      <p><![CDATA[hurixsystems]]></p>
    </simpleAssociableChoice>
    <simpleAssociableChoice identifier="W_4" matchMax="1">
      <p><![CDATA[aspire]]></p>
    </simpleAssociableChoice>
    <simpleAssociableChoice identifier="W_5" matchMax="1">
      <p><![CDATA[india]]></p>
    </simpleAssociableChoice>
    <simpleAssociableChoice identifier="W_6" matchMax="1">
      <p><![CDATA[kitab]]></p>
    </simpleAssociableChoice>
    <simpleAssociableChoice identifier="W_7" matchMax="1">
      <p><![CDATA[google]]></p>
    </simpleAssociableChoice>
    <simpleAssociableChoice identifier="W_8" matchMax="1">
      <p><![CDATA[australia]]></p>
    </simpleAssociableChoice>
    <simpleAssociableChoice identifier="W_9" matchMax="1">
      <p><![CDATA[elephant]]></p>
    </simpleAssociableChoice>
    <simpleAssociableChoice identifier="W_10" matchMax="1">
      <p><![CDATA[mumbai]]></p>
    </simpleAssociableChoice>
    <simpleAssociableChoice identifier="W_11" matchMax="1">
      <p><![CDATA[hyderabad]]></p>
    </simpleAssociableChoice>
    <simpleAssociableChoice identifier="W_12" matchMax="1">
      <p><![CDATA[chennai]]></p>
    </simpleAssociableChoice>
    <simpleAssociableChoice identifier="W_13" matchMax="1">
      <p><![CDATA[dictera]]></p>
    </simpleAssociableChoice>
  </simpleMatchSet>
</matchInteraction>
//bla bla..

形成上面的xml我试图获取数组包含p-tag值作为simpleMatchSet的子元素。
我的xpath查询是这样的

form the above xml i am trying to get array which contains "p-tag"values as a child of simpleMatchSet. my xpath query is like this

  NSString *xmlFilePath=[[NSBundle mainBundle]pathForResource:@"wordsearchmain" ofType:@"xml"];
NSData *data=[[NSData alloc]initWithContentsOfFile:xmlFilePath];

NSString *xpathQuery = [[NSString alloc] initWithFormat:@"assessmentItem/itemBody/matchInteraction/simpleMatchSet/../simpleAssociableChoice/p/text()"];
NSDictionary *results = PerformXMLXPathQuery(data, xpathQuery);
[xpathQuery release];

我不知道我在哪里错误地从xml.can获取数据任何人建议我纠正我的xpathQuery.Thanks all。所有可接受的建议。

i dont know where i did mistake to get data from the xml.can any one suggest me to correct my xpathQuery.Thanks all.All suggestions acceptable.

推荐答案

您尝试在XPath查询中匹配的元素位于命名空间中其URI是http://www.imsglobal.org/xsd/imsqti_v2p1。这是因为在顶级元素上有一个默认的名称空间声明:

The elements you are trying to match in your XPath query are in the namespace whose URI is "http://www.imsglobal.org/xsd/imsqti_v2p1". This is because on the top-level element there is a default namespace declaration:

xmlns="http://www.imsglobal.org/xsd/imsqti_v2p1" 

要匹配这些元素,您有两种选择:

To match these elements, you have two choices:


  1. 为http://www.imsglobal.org/xsd/imsqti_v2p1定义名称空间前缀,然后在XPath表达式中使用该前缀在每个元素名称之前,例如:
    imsq:assessmentItem / imsq:itemBody / imsq:matchInteraction / imsq:simpleMatchSet / imsq:simpleAssociableChoice / imsq:p / text()

将您的XPath表达式修改为名称空间不敏感,例如

modify your XPath expression to be namespace-insensitive, e.g.

// * [local-name()='simpleAssociableChoice'] // text()

这篇关于从iphone中的数组中的xml文件中获取零对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆