Re: [xml] Removing all of the xml:X attributes from a node



Daniel Veillard wrote:
On Fri, Mar 17, 2006 at 03:46:46PM -0800, Rush Manbert wrote:

I am trying to write a function that removes all attributes from an element using the tree interface. It seems that xml:lang, xml:id, and xml:space are special cases, since they have their own get and set functions.

Do I need to do anything special to remove these attributes from the node?


  No, they are normal attributes, only their namespace is special.


My current code for "remove all attributes" is this:

inline void
removeAllNodeAttributes (xmlNodePtr pNode)
{
   xmlAttrPtr pAttr;
   while (NULL != (pAttr = pNode->properties))
   {
       xmlRemoveProp (pAttr);
   }
}


  that should work. That won't remove namespace declarations, but that's
normal they are a different kind of nodes, and removing them is way harder.


Thanks Daniel, maybe this thread will work.

My apologies, I wrote xml:id when I means xml:base in the original post.

I can see that xml:base is applied to an element in the normal way. The W3C Recommendation has this example:
<doc xml:base="http://example.org/today/";
     xmlns:xlink="http://www.w3.org/1999/xlink";>

It makes sense that remove all attributes should remove that one. Or at least have the option of removing it.

However, xml:space only seems to appear in the DTD, within an <!ATTLIST>. Does that just end up adding a normal attribute named xml:space on every affected element, but it does it "behind the scenes"?

If I wanted to change my code to preserve xml:space and xml:base, would I just do a string compare of "xml" to xmlAttribute.prefix and, either "base" or "space" to xmlAttribute.name?

Thanks,
Rush





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