我对SimpleXML解析器有一个很大的问题(至少对我来说是这样)。错误是:
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
我用谷歌搜索过了,但一无所获。我还搜索了XML标记声明(可能禁止声明数字标记),但什么也没找到。您可以在下面找到我的xml (.meta)文件:
<?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>在第89行:
$ma = simplexml_load_file("file.meta");任何答案都是值得感谢的。提前谢谢。;)
发布于 2011-09-17 16:35:27
在标记名中使用数字是可以的-但以数字开头是不可以的……
http://www.w3schools.com/xml/xml_elements.asp
XML命名规则
XML元素必须遵循以下命名规则:
可以使用任何名称,不保留任何单词。
发布于 2011-09-17 16:35:52
您不能将数字作为元素名称。从Wikipedia article on XML
元素标记区分大小写;开始标记和结束标记必须完全匹配。标记名不能包含任何字符!"#$%&'()*+,/;<=>?@[]^`{|}~,也不能包含空格字符,不能以-,.,或数字开头。
发布于 2011-09-17 16:56:40
当然,你不应该以数字开头命名你的标签。这是一个问题。我建议您更改XML结构,因为它现在处理起来一点也不方便。例如:
<?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>然后,您可以使用以下代码非常容易地处理此XML:
$ma = simplexml_load_file("file.meta");
$sequence = $ma->xpath('Sequence/value');
foreach ($sequence as $el)
{
echo "Index: {$el['index']}, value: $el <br>";
}它将输出:
Index: 335, value: 1315815794
Index: 336, value: 1315815814
Index: 337, value: 1315815804 https://stackoverflow.com/questions/7453529
复制相似问题