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 


From: Eric Eberhard <fl...@vicsmba.com>
Sent: Thursday, August 29, 2019 5:31 PM
To: Lara Blatchford <lara.blatchf...@nteligen.com>; xml@gnome.org
Subject: 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-boun...@gnome.org] On Behalf Of Lara Blatchford
Sent: Wednesday, August 28, 2019 1:37 PM
To: xml@gnome.org<mailto: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="http://www.w3.org/2001/XMLSchema-instance";  


<?xml version="1.0"?>
<x1:address xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";  

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" 

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

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 

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.


xml mailing list, project page  http://xmlsoft.org/

Reply via email to