in reply to Re^3: LibXML setNodeName error (updated)
in thread LibXML setNodeName error

I've noticed a new issue. If the value of the name attribute contains the character "{" then I receive the error:
bad name at replaceelementname.pl line 8.
There may be other characters that causes this error as well. Any help would be appreciated. If I have to drop XML::LibXML completely, that is okay.

Replies are listed 'Best First'.
Re^5: LibXML setNodeName error
by haukex (Archbishop) on Jun 26, 2017 at 20:32 UTC

    So you have something like <xsl:element name="foo{bar">? That's not going to be valid as an XML element Name (<foo{bar>?), so what do you want the element to be named instead in that case?

    It's not an issue with XML::LibXML, which probably follows the XML spec precisely, but with XML itself. Also, as always, SSCCE - give us the shortest possible code that demonstrates the problem so we can see it.

      You are correct when I'm referring to an example like:
      <xsl:element name = "{foo}bar">
      In this instance, I would like that node to be left alone, unchanged. test input:
      <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" versi +on="1.0"> <xsl:element name="foo"> <xsl:element name="{bar}"/> </xsl:element> </xsl:stylesheet>
      test output:
      <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" versi +on="1.0"> <foo> <xsl:element name="{bar}"/> </xsl:element> </foo> </xsl:stylesheet>
      I'm sorry for changing the requirements.

        Well, in that case perhaps add next unless $el->getAttribute('name')=~/^\w+$/; into the loop I showed, or, since that might reject valid element names, reject the unwanted names with next if $el->getAttribute('name')=~/[\{\}]/;, adding more there as necessary.

        (Looking back at the original problem statement, I do have to say I'm not sure why you want to manipulate your XSL like this in the first place. XML and especially XSL is somewhat verbose in its nature...)