The namespace prefix is ​​undefined. How can I detect it automatically / ignore the error?

I created a PHP script that parses an XML file, and when I try to parse it, an error appears:

2: DOMDocument :: load (): edf namespace prefix for presentation on information is not defined in /users/zzz/testing/meta.xml, line: 2

I was looking for a fix, but I could not find it, so I post it here. As you can see, I am using a class DOMDocument.

My XML parsing code is as follows:

$dom = new DOMDocument();
$metaXML = $dom->load($path."/meta.xml");

The way and everything is right, I'm sure. When I remove the prefix, it works fine. XML looks like this:

<meta>
    <info gamemodes="race" type="map" edf:represent="false"></info>
</meta>

edf: Represent = "false" . edf, XML, . , .

, : ( XML) / DOMDocument class?

+4
2

, . , XML , . XML - .

namesapce . , xmlns. . script/, XML, , .

<meta xmlns:edf="urn:example">
    <info gamemodes="race" type="map" edf:represent="false"></info>
</meta>

. "edf: " "{urn: example} ".

, libxml_use_internal_errors().

$xml = <<<'XML'
<meta>
    <info gamemodes="race" type="map" edf:represent="false"></info>
</meta>
XML;

libxml_use_internal_errors(TRUE);

$dom = new DOMDocument();
$dom->loadXml($xml);

echo $dom->saveXml();

:

<?xml version="1.0"?>
<meta>
    <info gamemodes="race" type="map" represent="false"/>
</meta>

libxml_get_errors() .

, XML . , "" , . , represent {urn:example}represent - , .

+3

XML , . , , :

<meta xmlns:edf="http://www.example.com/">
    <info gamemodes="race" type="map" edf:represent="false"></info>
</meta>

: XML, XML . , , XML. , XML, XML .

@Daniel:


, , "sed", . , <meta <meta xmlns:edf="http://www.example.com/", .

sed -i -- 's/<meta/<meta\ xmlns\:edf\=\"http\:\/\/www.example.com\/\"/g' *

. https://unix.stackexchange.com/questions/112023/how-can-i-replace-a-string-in-a-files , sed.


XML XML, , , .

+2

All Articles