简体   繁体   中英

PHP simpleXml issue with several attributes

I have a xml node to create like this :

 <Document xmlns="blabla" xmlns:xsi="blablablabla" xsi:schemaLocation="blablablablablabla">

I did in my code several tests:

CASE 1

    $document = $this->_xml;
    $document->addAttribute('xmlns:xmlns', self::XMLNS);
    $document->addAttribute("xmlns:xsi", self::XMLNS_XSI);
    $document->addAttribute("xmlns:xsi:schemaLocation", self::XSI_SCHEMALOCATION);

which gives me :

<Document xmlns="blabla" xsi="blablablabla" xsi:schemaLocation="blablablablablabla">

So here all the xmln attributes are overriden by the xsi attribute.

CASE 2 When I add the prefix xmlns for last node :

    $document = $this->_xml;
    $document->addAttribute("xmlns:xsi", self::XMLNS_XSI, self::XMLNS);
    $document->addAttribute("xmlns:xsi:schemaLocation", self::XSI_SCHEMALOCATION);

which gives me :

<Document xmlns:xmlns="blabla" xmlns:xsi="blablablabla" xsi:schemaLocation="blablablabla">

CASE 3 and when I try the easiest version it totally fails :

    $document = $this->_xml;
    $document->addAttribute('xmlns', self::XMLNS);
    $document->addAttribute("xmlns:xsi", self::XMLNS_XSI);
    $document->addAttribute("xmlns:xsi:schemaLocation", self::XSI_SCHEMALOCATION);

which gives me :

<Document xmlns:xmlns="blabla" xmlns="blabla" xmlns:xsi="blablablabla" xsi:schemaLocation="blablablablablabla">

How can I have all my 3 attributes xmlns, xmlns:xsi and xsi:schemaLocation correctly in my node?

Please note that I solved a first issue thanks to this post : Unable add namespace with PHPs SimpleXML

Thanks

我修复了它,它在第一种情况下格式正确,但是Firefox无法正确解释该节点。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM