[xml] updating namespace prefix of QName



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">









<?xml version="1.0"?>

<x1:address xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”  xmlns:x1="http://namespaces.oreilly.com/xmlnut/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:element name="entry" type="entry" minOccurs="1" maxOccurs="unbounded"/>




  <xsd:complexType name="entry">


          <xsd:element name="rootElement" type="xsd:QName" />






An instance of the XML appears as follows:


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>



        <rootElement xmlns:ns="file:///testns">ns:outer</rootElement>




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.







[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]