I
I
Ilya Beloborodov2016-02-05 17:25:24
PHP
Ilya Beloborodov, 2016-02-05 17:25:24

How do I force a DOMDocument to close a tag the way I want?

I have in xml variable

<parent>
    <item atr="some"></item>
  </parent>

I keep it
$doc = new \DOMDocument();
$doc->loadXML($xml);
$doc->save(path);

and in the xml saved by the library I see this
<parent>
    <item atr="some"/>
  </parent>

The library removed the closing tag, and added a slash.
Everything would be fine, but I send this XML as a post to one remote server, to which I do not have access, and the server swears at such a format.
Maybe some flags?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2016-02-05
@salexseen

Try replacing $doc->save(path) with $doc->save(path, LIBXML_NOEMPTYTAG), then the library shouldn't remove the closing tag.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question