Python Element Tree Writing to New File

The ElementTree.write method defaults to us-ascii encoding and as such expects a file opened for writing binary: The output is either a string (str) or binary (bytes). This is controlled by the encoding argument. If encoding is “unicode”, the output is a string; otherwise, it’s binary. Note that this may conflict with the type of … Read more

Update XML node value in SQL Server

You can do something like this: UPDATE dbo.profiles SET ProfileXML.modify(‘replace value of (/ProblemProfile/GroupID/text())[1] with “0”‘) WHERE id = 23 Check out this article on SQL Server 2005 XQuery and XML-DML for more details on what you can do with the .modify keyword (insert, delete, replace etc.). Marc PS: In order to get the value, it … Read more

Maven resource filtering for single file

I don’t know why Gabor’s solution did not work, but I managed to solve this way: Firstly I removed nonFilteredFileExtension tag: <nonFilteredFileExtension>xml</nonFilteredFileExtension> Then modified my resources this way: <resource> <directory>src/main/resources</directory> <filtering>true</filtering> <includes> <include>**/myxml.xml</include> </includes> </resource> <resource> <directory>src/main/resources</directory> <filtering>false</filtering> <includes> <include>**/*.xml</include> </includes> </resource> Now my single xml file is filtered and other is leaved untouched by … Read more

Escaping special character when generating an XML in Java

You can use apache common lang library to escape a string. org.apache.commons.lang.StringEscapeUtils String escapedXml = StringEscapeUtils.escapeXml(“the data might contain & or ! or % or ‘ or # etc”); But what you are looking for is a way to convert any string into a valid XML tag name. For ASCII characters, XML tag name must … Read more

What is the difference between localname and qname?

The qualified name includes both the namespace prefix and the local name: att1 and foo:att2. Sample XML <root xmlns=”http://www.example.com/DEFAULT” att1=”Hello” xmlns:foo=”http://www.example.com/FOO” foo:att2=”World”/> Java Code: att1 Attributes without a namespace prefix do not pick up the default namespace. This means while the namespace for the root element is “http://www.example.com/DEFAULT”, the namespace for the att1 attribute is … Read more

How to check if an attribute exists in a XML file using XSL

Here is a very simple way to do conditional processing using the full power of XSLT pattern matching and exclusively “push” style, and this even avoids the need to use conditional instructions such as <xsl:if> or <xsl:choose>: <xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”> <xsl:output omit-xml-declaration=”yes” indent=”yes”/> <xsl:template match=”/root/diagram[graph[1]/@color]”> Graph[1] has color </xsl:template> <xsl:template match=”/root/diagram[not(graph[1]/@color)]”> Graph[1] has not color … Read more