> While I think this would make SimpleXML more stupid, not less, as it > seems > braindead to me to allow users to create documents ambiguously and/or > which > essentially violate the XML namespace spec, I think the way to do
Allowing child elements to be unqualified is neither braindead or ambiguous. All standalone XML documents are ambiguous, because XML is just structured information without a definition of the structure (let alone the semantics of the information). XMLSchemas precisely define the structure, including allowable elements, child elements, quantities of elements and data types. And if that schema includes the attribute 'elementFormDefault="unqualified"', then child elements have to be unqualified. And that is certainly strictly specified, unlike a schemaless XML. In fact, it would save a lot of time, if SimpleXML had a schema mode, and could validate and parse XML based on a provided schema. XMLReader has validation support, but it doesn't use the schema for binding XML elements to a data structure. > this would be to > define a magic constant and use that. E.g. > > const SIMPLEXML_DEFAULT_UNPREFIXED = 0 > > I used 'default unprefixed' to better describe what is going to > happen in terms of > namespaces (as within the context of a namespaced document is the > only time this > would be needed): the element is going to be created in the default > namespace by > virtue of being unprefixed. This highlights to the user the ambiguity > involved (it > is not necessarily known what the default namespace is at any point), > as well as > the 'priority' the XML generation will take at that point (of adding > an unprefixed > element). > -1 for using "unqualified"; whatever is used should not be a possibly > valid > namespace name. Well, it is possible to examine the type, so (int) -1 is distinct from "-1", so there is no risk of considering it an actual namespace. So, like this: $sxe->addChild('child', 123); # Adds element with namespace inherited from the parent $sxe->addChild('child', 123, 'urn:somenamespace'); # Adds child with specified namespace $sxe->addChild('child', 123, -1); # Adds child with no namespace qualification That wouldn't be hard to do. But I don't really want to create a patch, unless someone will accept it. > Ben. Tom -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php