Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here



How can I obscure my XML before posting? by k5tm
Posted: 14 Feb 14

One problem some face when posting to the XML forum is the need to maintain the privacy of proprietary data contained in an XML document. So, the poster will often try to paraphrase the XML document that is at issue and in the process mis-state the structure in a way that leads to miscommunication.

The following XSLT does a reasonable job of obscuring both the XML element and attribute names, and the data, in an XML document.


<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding="utf-8"/>
<xsl:variable name="myTranslate" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'"/>

<xsl:template match="/">
	<xsl:apply-templates select="*"/>

<xsl:template match="*">
<xsl:variable name="myName"><xsl:call-template name="obfuscate">
 							<xsl:with-param name="theString" select="local-name()"/>
<xsl:element name="{$myName}" namespace="{namespace-uri()}">
	<xsl:apply-templates select="@*"/>
	<xsl:apply-templates select="* | text() | comment()"/>

<xsl:template match="@*">
<xsl:variable name="myName"><xsl:call-template name="obfuscate">
 							<xsl:with-param name="theString" select="local-name()"/>
<xsl:attribute name="{$myName}" namespace="{namespace-uri()}"><xsl:call-template name="obfuscate">
 							<xsl:with-param name="theString" select="."/>

<xsl:template match="text()"><xsl:call-template name="obfuscate">
 							<xsl:with-param name="theString" select="."/>

<xsl:template name="obfuscate">
<xsl:param name="theString"/>
<xsl:param name="theTranslate" select="$myTranslate"/>
<xsl:param name="stringSoFar" select="''"/>
<xsl:when test="string-length($theString)=0"><xsl:value-of select="$stringSoFar"/></xsl:when>
<xsl:otherwise><xsl:call-template name="obfuscate">
				<xsl:with-param name="theString" select="substring($theString,2)"/>
				<xsl:with-param name="theTranslate" select="concat(substring($theTranslate,2,51),substring($theTranslate,1,1),substring($theTranslate,54,9),substring($theTranslate,53,1))"/>
				<xsl:with-param	name="stringSoFar" select="concat($stringSoFar,translate(substring($theString,1,1),'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',$theTranslate))"/>


This works well on Saxon, and reasonably well on MSXML.

You can change the string defined for myTranslate as you see fit. The obfuscate template shifts the upper case letters, lower case letters and numbers each as a group for each level of recursion. Therefore you might want to group your upper case, lower case and numbers together as in the example. Especially for the numbers, keeping the numbers together allows the obfuscator to produce number strings where there were numbers in the original.

Namespaces are not obfuscated, so this will be something you must do yourself if necessary. (There is no way to match namespace nodes in a template in XSLT/XPath version 1, so obfuscating namespace values would have introduced more complexity for very little benefit.)

Back to XML FAQ Index
Back to XML Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close