@@ -45,6 +45,38 @@ public function testParseFragment()
4545 $ this ->readDumpAssertFragment ('<tag xmlns="urn:test">Foo</tag> ' );
4646 }
4747
48+ public function testDefaultNamespaceOnInnerElementIsNotPrefixed ()
49+ {
50+ $ this ->markTestSkipped ('Pending bugs in PHP: https://bugs.php.net/bug.php?id=47530, https://bugs.php.net/bug.php?id=55294 ' );
51+
52+ /*
53+ * In this example, "tag" is from the "urn:first" namespace and "inner" is from "urn:second".
54+ *
55+ * One could expect that parsing and re-serializing this fragment does not need to change the resulting
56+ * XML at all. However, some internals in libxml try to merge namespace declarations on common ancestor nodes
57+ * and lead to the declaration of "default" and "default1" namespace prefixes on the "outer" element;
58+ * <tag> and <inner> are rewritten to <default:tag> and <default1:inner>.
59+ * Note that this has nothing to do with the default namespace; it's something internal to libxml.
60+ *
61+ * From xmlNewReconciliedNs in libxml's tree.c:
62+ * This function tries to locate a namespace definition in a tree
63+ * ancestors, or create a new namespace definition node similar to
64+ * @ns trying to reuse the same prefix. However if the given prefix is
65+ * null (default namespace) or reused within the subtree defined by
66+ * @tree or on one of its ancestors then a new prefix is generated.
67+ * Returns the (new) namespace definition or NULL in case of error
68+ *
69+ * Now, technically, this does not make a difference as the elements are still associated with the
70+ * original namespace. However, it does make a difference when embedding <svg> in HTML, for example,
71+ * when User Agents are not using a XML parser and do not honor the namespace declarations.
72+ *
73+ * In this case,
74+ * http://stackoverflow.com/questions/18467982/are-svg-parameters-such-as-xmlns-and-version-needed
75+ * suggests to simply omit the xmlns declaration for the <svg> element.
76+ */
77+ $ this ->readDumpAssertFragment ('<outer><tag xmlns="urn:first"><inner xmlns="urn:second"></inner></tag></outer> ' );
78+ }
79+
4880 /**
4981 * @expectedException \Webfactory\Dom\Exception\ParsingException
5082 */
@@ -163,15 +195,15 @@ public function testXPathExpressionAndNodeListDump()
163195 }
164196
165197 /**
166- * @expectedException Webfactory\Dom\Exception\EmptyXMLStringException
198+ * @expectedException \ Webfactory\Dom\Exception\EmptyXMLStringException
167199 */
168200 public function testParsingEmptyDocumentFails ()
169201 {
170202 $ this ->parser ->parseDocument ('' );
171203 }
172204
173205 /**
174- * @expectedException Webfactory\Dom\Exception\EmptyXMLStringException
206+ * @expectedException \ Webfactory\Dom\Exception\EmptyXMLStringException
175207 */
176208 public function testParsingEmptyFragmentFails ()
177209 {
0 commit comments