0

Say I have an XML file like

    <root> 
     <h:table>
      <h:tr> we have
        <h:td>Apples</h:td>,
        <h:td>Bananas</h:td>,
      </h:tr>
    </h:table>
    <f:table>
      <f:name>African Coffee Table</f:name>,
      <f:width>80</f:width>,
      <f:length>120</f:length>,
    </f:table>
  </root>

Notice how the text in <h:tr> and the text in <f:table> is interspersed with other tags. My ultimate goal is to print this list as "we have Apples, Bananas, African Coffee Table, 80, 120" but I don't know how to get only the "we have" portion of the text.

Thus far I have attempted to use

func enumerate(indexer: XMLIndexer) {
    for child in indexer.children {
        print(child.element!.text)
        enumerate(child)
    }
}

enumerate(indexer: exampleXML)

However that prints "we have , , Apples Bananas , , , African Coffee Table 80 120." The root of the problem is that exampleXML["root"]["h:table"]["h:tr"].element!.text returns "we have , ," while I would like to first get the "we have" portion and print it, then print "Apples", then get the "," and print it, etc. I simply have no idea what syntax I should use to do this. Does anyone know how to do this with SWXMLHash or with a different method in Swift?

0 Answers0