Hello, I need to be able to rewrite all namespace prefixes in XML documents. While traversing the DOM tree, I am able to iterate over the nsDef entries in an xmlNode and replace the value of the xmlNs prefix. This neatly updates the prefixes
of all elements associated with this prefix. For example, resetting the prefix in the xmlNs node associated with xmlns:addr to “x1” transforms
<?xml version="1.0"?> <addr:address xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:addr="http://namespaces.oreilly.com/xmlnut/address"> <addr:fullName> <addr:first>Scott</addr:first> <addr:last>Means</addr:last> </addr:fullName> </addr:address> into <?xml version="1.0"?> <x1:address xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:x1="http://namespaces.oreilly.com/xmlnut/address"> <x1:fullName> <x1:first>:Scott</x1:first> <x1:last>Means</x1:last> </x1:fullName> </x1:address> So far so good. However, this method does not work for elements of type QName. For example, the following schema defines a sequence of rootElement elements, which are QNames. <?xml version="1.0"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="XFP" type="XFP"/> <xsd:complexType name="XFP"> <xsd:sequence> <xsd:element name="entry" type="entry" minOccurs="1" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> <xsd:complexType name="entry"> <xsd:sequence> <xsd:element name="rootElement" type="xsd:QName" /> </xsd:sequence> </xsd:complexType> </xsd:schema> An instance of the XML appears as follows: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <XFP> <entry> <rootElement xmlns:ns="file:///testns">ns:outer</rootElement> </entry> </XFP> If I reset the prefix in the xmlNs node associated with xmlns:ns in the rootElement in this case, the prefix on the text content “ns:outer” is not updated. Testing with libxml2 2.9.7 showed that the xmlNode psvi pointer was always null, so I see no way to identify the element as a QName. Is there a way to get PSVI information populated, or is PSVI information is still not available? Or there
another way to solve this problem? Suggestions appreciated. Thanks, Lara |