0

I am in the process of writing some code to parse questions into objects. I am using NSXMLParser. The problem is, I also formatted my own XML data, and I think it is incorrect.

<?xml version="1.0" encoding="UTF-8"?>
<factor value="1">
    <key value="plus">
        <question>PLACEHOLDER_TEXT</question>
        <question>PLACEHOLDER_TEXT</question>
        <question>PLACEHOLDER_TEXT</question>
        <question>PLACEHOLDER_TEXT</question>
        <question>PLACEHOLDER_TEXT</question>

    </key>
    <key value="minus">
        <question>PLACEHOLDER_TEXT</question>
        <question>PLACEHOLDER_TEXT</question>
        <question>PLACEHOLDER_TEXT</question>
        <question>PLACEHOLDER_TEXT</question>

    </key>
</factor>
<factor value="2">
    <key value="plus">
        <question>PLACEHOLDER_TEXT</question>
        <question>PLACEHOLDER_TEXT</question>
        <question>PLACEHOLDER_TEXT</question>
        <question>PLACEHOLDER_TEXT</question>
        <question>PLACEHOLDER_TEXT</question>
    </key>
    <key value="minus">
        <question>PLACEHOLDER_TEXT</question>
        <question>PLACEHOLDER_TEXT</question>
        <question>PLACEHOLDER_TEXT</question>
        <question>PLACEHOLDER_TEXT</question>
        <question>PLACEHOLDER_TEXT</question>
    </key>
</factor>

That is the xml im am parsing. Halfway through the questions, the parser gives me Error Domain=NSXMLParserErrorDomain Code=5 "The operation couldn’t be completed. (NSXMLParserErrorDomain error 5.)"

My Question: How can I format this so that the entire document is parsed correctly. The end result is to have a question managed object with attributes of:key, and factor.

scord
  • 1,375
  • 1
  • 17
  • 34

2 Answers2

1

You have two root elements, <factor>. A well-formed XML document can only have one root element.

Ned Batchelder
  • 364,293
  • 75
  • 561
  • 662
1

I would recommend putting all your <factor> into a root tag called <factors> so you can iterate over it to get all your <factor>

Oscar Gomez
  • 18,436
  • 13
  • 85
  • 118
  • does that need any special formatting? I tried that by enclosing it in but it did not work. – scord Jul 03 '12 at 01:35