复杂的XML解析到标签

时间:2014-04-07 10:05:44

标签: ios xml

嗨,大家好我是一个新手iOS Pragrammer,我必须在某些标签中解析这个XML的“Value”标签。 我对相同的标签感到困惑。 我不期望解决方案,如果有人能给我一个解释如何为这个XML示例制作代码的解释,那就太棒了。 我感谢任何回应和帮助。

<?xml version="1.0" encoding="ISO-8859-1"?>
<Statistics xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
xsi:noNamespaceSchemaLocation="">
<Statistics>
<Statistic>
  <Name>heute</Name>
  <Statistic>
    <Name>Bestellungen heute</Name>
    <Value>12</Value>
  </Statistic>
  <Statistic>
    <Name>Umsatz heute netto</Name>
    <Value>7225,97</Value>
  </Statistic>
</Statistic>
<Statistic>
  <Name>Allgemein</Name>
  <Statistic>
    <Name>Online</Name>
    <Value>2495</Value>
  </Statistic>
  <Statistic>
    <Name>Lager</Name>
    <Value>448</Value>
  </Statistic>
  <Statistic>
    <Name>Auslauf</Name>
    <Value>29</Value>
  </Statistic>
  <Statistic>
    <Name>Keine Features</Name>
    <Value>0</Value>
  </Statistic>
  <Statistic>
    <Name>Reservierungen</Name>
    <Value>163</Value>
  </Statistic>
  <Statistic>
    <Name>Aufträge</Name>
    <Value>44100</Value>
  </Statistic>
  <Statistic>
    <Name>Abholer</Name>
    <Value>0</Value>
  </Statistic>
  <Statistic>
    <Name>Vorkasse</Name>
    <Value>8</Value>
  </Statistic>
  <Statistic>
    <Name>Nachnahme</Name>
    <Value>1</Value>
  </Statistic>
  <Statistic>
    <Name>Kreditkarte</Name>
    <Value>0</Value>
  </Statistic>
  <Statistic>
    <Name>Paypal</Name>
    <Value>3</Value>
  </Statistic>
  <Statistic>
    <Name>Sofortüberweisung</Name>
    <Value>0</Value>
  </Statistic>
  <Statistic>
    <Name>Finanzierung</Name>
    <Value>0</Value>
  </Statistic>
  <Statistic>
    <Name>Amazon</Name>
    <Value>0</Value>
  </Statistic>
  <Statistic>
    <Name>Neue Emails</Name>
    <Value>28</Value>
  </Statistic>
  <Statistic>
    <Name>Fragen</Name>
    <Value>10</Value>
  </Statistic>
  <Statistic>
    <Name>Termine</Name>
    <Value>4</Value>
  </Statistic>
</Statistic>

1 个答案:

答案 0 :(得分:0)

您需要创建一个NSXMLParser实例和一个类作为其delegate。您将获得有关找到的密钥及其包含的文本的回调。如果您不关心大多数密钥,那么您可以忽略它们。对于您关心的密钥,存储收到的文本,每次告知密钥完成后,将结果添加到NSMutableArray

现在,解析完成后,您将拥有一个充满Value s。

的数组

在标签上显示这些值比使用UITableView更难,所以请看一下。您可以使用该数组作为数据源,因为它为您提供了所需的count行,并且可以使用表视图indexPath.row访问它以获得每行显示的Value(和行包含您可以使用的标签。