I am trying to parse a simple config file with minimized Boolean attributes and the DOMDocument is not having it. I am trying to load the following:
<config>
<text id='name' required>
<label>Name:</label>
</text>
</config>
with the following code
$dom = new DOMDocument();
$dom->preserveWhiteSpace=FALSE;
if($dom->LoadXML($template) === FALSE){
throw new Exception("Could not parse template");
}
I am getting a warning that
Warning: DOMDocument::loadXML(): Specification mandate value for attribute required in Entity, line: 2
Am I missing a flag or something to get DOMDocument to parse the minimum boolean attribute?
An attribute without a value is not valid syntax in either XML 1.0 or 1.1, so what you have isn't XML. You should get that fixed.
Pretending that's not possible, you can use:
instead, which uses a parsing mode that's much more forgiving, but you'll get warnings about invalid HTML tags. So you'll also need
libxml_use_internal_errors(true)
andlibxml_get_errors()
(which you should probably be using anyway to deal with errors) and ignore anything with an error code of 801.Example:
Outputs: