robrichards / xmlseclibs

A PHP library for XML Security
BSD 3-Clause "New" or "Revised" License
387 stars 181 forks source link

Indentation #166

Closed quimm2003 closed 2 years ago

quimm2003 commented 6 years ago

Hi there,

Just to inform.

I'm working in a project where all xml nodes must be indented to be accepted by a remote server. So I've tweaked the XMLSecurityDsig constructor like this:

    public function __construct($prefix='ds', $formatOutput=FALSE)
    {
        $template = self::BASE_TEMPLATE;
        if (! empty($prefix)) {
            $this->prefix = $prefix.':';
            $search = array("<S", "</S", "xmlns=");
            $replace = array("<$prefix:S", "</$prefix:S", "xmlns:$prefix=");
            $template = str_replace($search, $replace, $template);
        }
        $sigdoc = new DOMDocument();
        if ($formatOutput === TRUE) {
            $sigdoc->preserveWhiteSpace = FALSE;
            $sigdoc->formatOutput = TRUE;
        }
        $sigdoc->loadXML($template);
        $this->sigNode = $sigdoc->documentElement;
    }

And get the final xml properly indented.

Thank you all.