Formatage du fichier dcstore.xml #4

Closed
opened 2021-11-05 07:59:34 +00:00 by franck-paul · 0 comments
franck-paul commented 2021-11-05 07:59:34 +00:00 (Migrated from github.com)

Une petite suggestion : indenter le fichier dcstore.xml produit par le plugin avec (par exemple) :

$str = <<<EOF
<modules xmlns:da="http://dotaddict.org/da/">
<module id="improve">
<name>improve</name>
<version>0.4</version>
<author>Jean-Christian Denis and contributors</author>
<desc>Tiny tools to fix things for module devs</desc>
<file>https://github.com/JcDenis/improve/releases/download/v0.4/plugin-improve.zip</file>
<da:dcmin>2.19</da:dcmin>
<da:details>https://github.com/JcDenis/improve</da:details>
<da:support>https://github.com/JcDenis/improve</da:support>
</module>
</modules>
EOF;

$prettyXML = function (string $str = ''): string {
    if (class_exists('DOMDocument')) {
        $dom = new DOMDocument('1.0');

        $dom->preserveWhiteSpace = false;
        $dom->formatOutput       = true;

        $dom->loadXML($str);

        return $dom->saveXML();
    }

    return $str;
};

$xml_pretty = $prettyXML($str);
Une petite suggestion : indenter le fichier `dcstore.xml` produit par le plugin avec (par exemple) : ```php $str = <<<EOF <modules xmlns:da="http://dotaddict.org/da/"> <module id="improve"> <name>improve</name> <version>0.4</version> <author>Jean-Christian Denis and contributors</author> <desc>Tiny tools to fix things for module devs</desc> <file>https://github.com/JcDenis/improve/releases/download/v0.4/plugin-improve.zip</file> <da:dcmin>2.19</da:dcmin> <da:details>https://github.com/JcDenis/improve</da:details> <da:support>https://github.com/JcDenis/improve</da:support> </module> </modules> EOF; $prettyXML = function (string $str = ''): string { if (class_exists('DOMDocument')) { $dom = new DOMDocument('1.0'); $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $dom->loadXML($str); return $dom->saveXML(); } return $str; }; $xml_pretty = $prettyXML($str); ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: JcDenis/improve#4
No description provided.