Page 1 of 1

simplexml_load_file() errors.

Posted: Thu Jun 07, 2012 2:43 am
by social_experiment
I wrote a script the uses simplexml_load_file() to parse a file; when parsing a specific file i receive these error messages
Warning: simplexml_load_file() [function.simplexml-load-file]: files/07 Jun/(12) doors_locks_2012_06_06_17_01.xml:8359: parser error : Opening and ending tag mismatch: Question line 8353 and ParentSubjectID

The element in question looks like this

Code: Select all

<Question>
            <Text>Panic Door devices (Weekly):

3. Are all fixings secure, check for wear, are there any visible worn components</Text>
            <QuestionID>qu_011</QuestionID>
            <Index>12</Index>
            <Variable>Q_12</Variable>
            <QType>eqtAmerican</QType>
            <QuestionAnswer>N/A</QuestionAnswer>
            <Answers>
              <Answer>
                <IsOtherSpec>False</IsOtherSpec>
                <Text>N/A</Text>
                <Index>3</Index>
                <AnswerID>5</AnswerID>
                <Code>3</Code>
                <AnswerShortID>an_011_006</AnswerShortID>
                <AnswerVariable>A_qu_011_3</AnswerVariable>
              </Answer>
            </Answers>
          </Question>
My thinking is telling me the problem is happening because of the whitespace inside the <Text> element. Is there any way to deal with this? One answer i found suggests using DOMDocument to load the document first and then using simplexml to parse the document.

Re: simplexml_load_file() errors.

Posted: Thu Jun 07, 2012 11:53 am
by Celauran
Cannot duplicate.

Re: simplexml_load_file() errors.

Posted: Thu Jun 07, 2012 9:03 pm
by requinix
social_experiment wrote:The element in question
Hurr.

The whitespace is fine and I don't see anything wrong. Which lines are 8353 and 8359? Are you passing any libxml options?

Re: simplexml_load_file() errors.

Posted: Fri Jun 08, 2012 12:47 am
by social_experiment

Code: Select all

          <Question>
            <Text>Panic Door devices (Weekly):

3. Are all fixings secure, check for wear, are there any visible worn components</Text>
            <QuestionID>qu_011</QuestionID>
            <Index>12</Index>
            <Variable>Q_12</Variable>
Above is line 8353 - 8359. No i'm not using any libxml options;
Celauran wrote:Cannot duplicate.
Could you elaborate on this a bit more?

Re: simplexml_load_file() errors.

Posted: Fri Jun 08, 2012 7:02 am
by Celauran
I copy/pasted the XML you posted above, called simplexml_load_file on it, and it worked fine. The issue must be elsewhere in the code.

Re: simplexml_load_file() errors.

Posted: Fri Jun 08, 2012 7:24 am
by social_experiment
i see; i did that earlier and couldn't reproduce the problem either. I've decided to try a suggestion i found elsewhere which involves loading the document with loadXML() and the parsing it and from there use simplexml_load_string() as opposed to simplexml_load_file()

Re: simplexml_load_file() errors.

Posted: Mon Jun 11, 2012 4:59 am
by social_experiment
I think i might be dealing with a corrupted xml file. I tested an existing file from a previous export and one i exported this morning and the code does what it is supposed to.