Re: [xml] updating namespace prefix of QName

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.




From: xml [mailto:xml-bounces gnome org] On Behalf Of Lara Blatchford
Sent: Wednesday, August 28, 2019 1:37 PM
To: xml gnome org
Subject: [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=””  xmlns:addr="">









<?xml version="1.0"?>

<x1:address xmlns:xsi=””  xmlns:x1="">







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


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