0

I have a big problem (at least for me ;)) with SimpleXML parser. The error is:

Warning: simplexml_load_file(): file.meta:16: parser error : StartTag: invalid element name in index.php on line 89
Warning: simplexml_load_file(): <335> in index.php on line 89
Warning: simplexml_load_file(): ^ in index.php on line 89
Warning: simplexml_load_file(): file.meta:18: parser error : expected '>' in index.php on line 89
Warning: simplexml_load_file(): in index.php on line 89
Warning: simplexml_load_file(): ^ in index.php on line 89
Warning: simplexml_load_file(): file.meta:18: parser error : Opening and ending tag mismatch: Sequence line 15 and unparseable in index.php on line 89
Warning: simplexml_load_file(): in index.php on line 89
Warning: simplexml_load_file(): ^ in index.php on line 89
Warning: simplexml_load_file(): file.meta:19: parser error : StartTag: invalid element name in index.php on line 89
Warning: simplexml_load_file(): <337> in index.php on line 89
Warning: simplexml_load_file(): ^ in index.php on line 89
Warning: simplexml_load_file(): file.meta:21: parser error : expected '>' in index.php on line 89
Warning: simplexml_load_file(): in index.php on line 89
Warning: simplexml_load_file(): ^ in index.php on line 89
Warning: simplexml_load_file(): file.meta:21: parser error : Opening and ending tag mismatch: MetaAttack line 2 and unparseable in index.php on line 89
Warning: simplexml_load_file(): in index.php on line 89
Warning: simplexml_load_file(): ^ in index.php on line 89
Warning: simplexml_load_file(): file.meta:21: parser error : Extra content at the end of the document in index.php on line 89
Warning: simplexml_load_file(): in index.php on line 89
Warning: simplexml_load_file(): ^ in index.php on line 89
Warning: Invalid argument supplied for foreach() in index.php on line 97

I've googled it but got nothing. I searched for XML tag declaration also (maybe its forbidden to declare a number tag) but found nothing. Below you can find my xml (.meta) file:

<?xml version="1.0"?>                                                                                                                                                   
<MA>
    <Count>
        3
    </Count>
    <Duration>
        34
    </Duration>
    <End>
        1315815814
    </End>
    <Start>
        1315815780
    </Start>
    <Sequence>
        <335>
            1315815794
        </335>
        <337>
            1315815814
        </337>
        <336>
            1315815804
        </336>
    </Sequence>
</MA>

On line 89:

$ma = simplexml_load_file("file.meta");

Any answer is appreciated. Thanks in advance. ;)

0

3 Answers 3

6

Using numbers in tag names is ok - but starting with number is not ok...

http://www.w3schools.com/xml/xml_elements.asp

XML Naming Rules

XML elements must follow these naming rules:

  • Names can contain letters, numbers, and other characters
  • Names cannot start with a number or punctuation character
  • Names cannot start with the letters xml (or XML, or Xml, etc)
  • Names cannot contain spaces

Any name can be used, no words are reserved.

Sign up to request clarification or add additional context in comments.

Comments

1

You can't have numbers as element names. From the Wikipedia article on XML:

The element tags are case-sensitive; the beginning and end tags must match exactly. Tag names cannot contain any of the characters !"#$%&'()*+,/;<=>?@[]^`{|}~, nor a space character, and cannot start with -, ., or a numeric digit.

Comments

0

Well definetely you should not name your tags starting with a number. This is a problem here. I would recommend you to change XML structure as it's not convinient right now at all to deal with. For instance:

<?xml version="1.0"?>
<MA>
    <Count>3</Count>
    <Duration>34</Duration>
    <End>1315815814</End>
    <Start>1315815780</Start>
    <Sequence>
        <value index="335">1315815794</value>
        <value index="336">1315815814</value>
        <value index="337">1315815804</value>
    </Sequence>
</MA>

Then you would proccess this XML pretty easy with the code:

$ma = simplexml_load_file("file.meta");
$sequence = $ma->xpath('Sequence/value');

foreach ($sequence as $el)
{
    echo "Index: {$el['index']}, value: $el <br>";
}

Which will output:

Index: 335, value: 1315815794 
Index: 336, value: 1315815814 
Index: 337, value: 1315815804 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.