Associate
- Joined
- 14 Apr 2003
- Posts
- 1,101
Hi guys,
This is driving me nuts. I am using PHP to output some XML to the screen (depending on the URL they browse to) and I have to use namespaces with my XML.
I have the following PHP code:
Obviously there are bits missing (thats not important). What I am noticing is that when you generate the XML it doesn't seem to remember which namespaces have been declared so has to write them out every time it uses one. This results in some pretty ugly looking XML. Also, on a more serious note, if I have an element with an attribute both in the same namespace it actually generates invalid XML by declaring the namespace twice in the same element (once for element, once for attribute).
Is there any way to tell the XMLWriter object to remember the namespaces it has written? My experience of PHP & XML so far have been pretty dire tbh
just to show you what i mean:
The second GML namespace declaration is not needed as it is declared in the parent node.
This is driving me nuts. I am using PHP to output some XML to the screen (depending on the URL they browse to) and I have to use namespaces with my XML.
I have the following PHP code:
PHP:
$xml = new XMLWriter();
$xml->openMemory();
$xml->startDocument();
$xml->startElementNS("un", "DistributionDefinition", "http://www.somenamespace.com");
$xml->writeAttributeNS("gml", "id", "http://www.opengis.net/gml", "DISTN_" . $dist_id);
$xml->writeElementNS("gml", "description", "http://www.opengis.net/gml", $descriptions[0]);
Obviously there are bits missing (thats not important). What I am noticing is that when you generate the XML it doesn't seem to remember which namespaces have been declared so has to write them out every time it uses one. This results in some pretty ugly looking XML. Also, on a more serious note, if I have an element with an attribute both in the same namespace it actually generates invalid XML by declaring the namespace twice in the same element (once for element, once for attribute).
Is there any way to tell the XMLWriter object to remember the namespaces it has written? My experience of PHP & XML so far have been pretty dire tbh

just to show you what i mean:
PHP:
<gml:Dictionary xmlns:gml="http://www.opengis.net/gml" id="DISTRIBUTIONS">
<gml:description xmlns:gml="http://www.opengis.net/gml">This is a dictionary describing ALL available distribution definitions</gml:description>
The second GML namespace declaration is not needed as it is declared in the parent node.
Last edited: