Hi Eric – thanks for the response. I’m writing a C program to change the XML as it is, but I can’t safely change the prefix on the QName value unless I know that it is a QName, which is why the lack of schema info is an issue. So whatever
the small C program you suggest could do, I can do in my application, but I’m not sure how to get that knowledge of the QName. Am I missing something? Thanks, Lara From: Eric Eberhard <flash vicsmba com> In these weird cases – and I have a few – if you have the performance for your task, just load it as is (or as you created) then write to disk. Have a small C program change it. Reload it. Tacky but always
works. Simple too. Slightly less performance which if that matters is a bad idea. I have found that on new machines performance is not an issue. Eric From: xml [mailto:xml-bounces gnome org]
On Behalf Of Lara Blatchford 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 |