Masking XML files

This walkthrough explains how to mask an XML document.

You are going to build a package that loads the given XML file, performs masking on XML elements and creates a new file with applied masking.

Table of contents
Preconditions
Loading and saving an XML file
Masking XML elements

Preconditions

  • BizDataX Package (Visual Studio project) is created.
  • XML file prepared.

In this walkthrough we are going to use XML file with following content:

<?xml version="1.0" encoding="utf-8" ?>
<Customers>
  <Customer CustomerID="1" FirstName="Orlando" LastName="Gee">
    <EmailAddress>orlando0@gmail.com</EmailAddress>
    <SSN>149362496</SSN>
    <Phone>245-555-0173</Phone>
  </Customer>
  <Customer CustomerID="2" FirstName="Keith" LastName="Harris">
    <EmailAddress>keith0@hotmail.com</EmailAddress>
    <SSN>961-65-9945</SSN>
    <Phone>170-555-0127</Phone>
  </Customer>
  <Customer CustomerID="3" FirstName="Donna" LastName="Carreras">
    <EmailAddress>donna0@yahoo.com</EmailAddress>
    <SSN>896-18-4813</SSN>
    <Phone>279-555-0130</Phone>
  </Customer>
  <Customer CustomerID="4" FirstName="Janet" LastName="Gates">
    <EmailAddress>janet1@gmail.com</EmailAddress>
    <SSN>111-58-6594</SSN>
    <Phone>710-555-0173</Phone>
  </Customer>
  <Customer CustomerID="5" FirstName="Kathleen" LastName="Garza">
    <EmailAddress>kathleen0@gmail.com</EmailAddress>
    <SSN>756525335</SSN>
    <Phone>150-555-0127</Phone>
  </Customer>
</Customers>

Loading and saving an XML file

In this part we will create simple package that only loads XML file and creates a new version of same XML file.

Load the XML file

  • In order to load the XML file, we need a variable to load the file into. Open the Variables tab in the bottom of Package.xaml window (Figure 1). Click on Create variable. New row is added. Enter xml as variable name.

Creating a new variable Figure 1: Creating a new variable in the Variables tab

Expand Variable type dropdown, and click Browse for Types (Figure 2).

Browsing for the variable type Figure 2: Browsing for the variable type

New window will open (Figure 3). Navigate to System.Xml.Linq -> System.Xml.Linq -> XDocument and click OK.

Selecting XDocument as the variable type Figure 3: Selecting XDocument as the variable type

  • Load xml file into variable.

Open the Toolbox. Find Assign tool under Primitives group. Drag and drop Assign tool into Package.xaml -> Sequence.

Enter xml as the variable in which to assign, and XDocument.Load(@"c:\temp\customersSample.xml") as the value to assign. Replace "c:\temp\customersSample.xml" with the path to your XML file.

Loading the XML file into a variable Figure 4: Loading the XML file into a variable

Save the new XML file

  • Add a tool for saving the file.

Open the Toolbox. Find InvokeMethod tool under Primitives group. Drag and drop InvokeMethod tool into Package.xaml -> Sequence, below the Assign tool. (Figure 5).

Enter variable name xml under TargetObject, Save as the Method name, and leave TargetType as null.

Adding the InvokeMethod tool for saving the file
Figure 5: Adding the InvokeMethod tool for saving the file

  • Define the new file name as the tool input parameter.

Select InvokeMethod tool in Package.xaml window, and open Visual studio Properties window. Click the browse button next to Parameters field. A window will open. Click on the Create argument. New row is created. Select In for Direction, String as Type, and enter @"c:\temp\customersSample_masked.xml" as the Value (Figure 6). Click OK.

Parameters window Figure 6: Parameters window

Execute package

  • Build and run package.
  • The build should be successful, and the package run should produce a new file on the defined location. The content of the file should be the same as the original XML file, because we still haven't defined any masking rules.

Masking XML elements

This part focuses on masking parts of the XML content.

Iterating through customers

  • Add a masking engine.

Double-click on Package.xaml in Solution Explorer to open the package designer.

Open the Toolbox. Drag and drop Masking engine tool from BizDataX Data Processing group into Package.xaml -> Sequence, below the Assign tool and above the InvokeMethod tool like in the (Figure 7).

Adding masking engine Figure 7: Adding masking engine

  • Add masking iterator.

Open the Toolbox. Drag and drop the Masking iterator activity from the BizDataX Data Processing group into the Masking engine.

  • When the Masking iterator is added, you will be prompted to select the type of entity to iterate over. Select Browse for Types, as displayed in Figure 8.

Adding masking iterator Figure 8: Adding masking iterator

  • New window with types is opened (Figure 9). Navigate to System.Xml.Linq -> System.Xml.Linq -> XElement and confirm with OK.

Browsing for type to iterate over Figure 9: Browsing for type to iterate over

  • Workflow should look like the one in Figure 10. Notice the Masking iterator user interface is divided into two areas: one for data handlers (Drop data handler here) and one for masking activities (Drop activities here).

Added masking iterator Figure 10: Added masking iterator

  • Add Enumerating handler (no tracking).

Open the Toolbox. Drag and drop Enumerating handler (no tracking) tool from BizDataX Data Processing group into Masking iterator where it says "Drop data handler here".

Enter xml.Descendants("Customer") for the Items.

Added Enumerating handler Figure 11: Added Enumerating handler (no tracking)

Mask xml element attribute

  • Mask First name attribute.

Open the Toolbox. Drag and drop Pick CH first name from list tool from BizDataX Country CH group into Masking iterator where it says "Drop activities here".

Select (expression) for the Property field and check the checkbox next to it. A textbox will appear to enter the expression. Enter current => current.Attribute("FirstName").Value. Select FirstName for the replace with field.

Masking first names Figure 12: Masking first names

  • Mask last name attribute.

Open the Toolbox. Drag and drop Pick CH last name from list tool from BizDataX Country CH group into Masking iterator below Pick CH first name from list.

Select (expression) for the Property field and check the checkbox next to it. A textbox will appear to enter the expression. Enter current => current.Attribute("LastName").Value. Select LastName for the replace with field.

Masking last names Figure 13: Masking last names

Mask xml element text content

  • Mask email

Open the Toolbox. Drag and drop Evaluate text function(item) tool from Primivites group into Masking iterator below Pick CH last name from list.

Select (expression) for the Property field and check the checkbox next to it. A textbox will appear to enter the expression. Enter current => current.Element("EmailAddress").Value. For the value to replace with, enter current => current.Attribute("FirstName").Value + "." + current.Attribute("LastName").Value + "@email.com".

Masking email Figure 14: Masking email

The finished workflow should look something like the one in Figure 15.

Finished workflow Figure 15: Finished workflow

Execute package

  • Build and run package.
  • The build should be successful, and the package run should produce a new file on the defined location. The content of the file should be changed, all the first names, last names and email should be masked.
<?xml version="1.0" encoding="utf-8"?>
<Customers>
  <Customer CustomerID="1" FirstName="Andrea" LastName="Ladnier">
    <EmailAddress>Andrea.Ladnier@email.com</EmailAddress>
    <SSN>149362496</SSN>
    <Phone>245-555-0173</Phone>
  </Customer>
  <Customer CustomerID="2" FirstName="Laurence" LastName="Glassey">
    <EmailAddress>Laurence.Glassey@email.com</EmailAddress>
    <SSN>961-65-9945</SSN>
    <Phone>170-555-0127</Phone>
  </Customer>
  <Customer CustomerID="3" FirstName="Renke" LastName="Loosli">
    <EmailAddress>Renke.Loosli@email.com</EmailAddress>
    <SSN>896-18-4813</SSN>
    <Phone>279-555-0130</Phone>
  </Customer>
  <Customer CustomerID="4" FirstName="Luciano" LastName="Leutzinger">
    <EmailAddress>Luciano.Leutzinger@email.com</EmailAddress>
    <SSN>111-58-6594</SSN>
    <Phone>710-555-0173</Phone>
  </Customer>
  <Customer CustomerID="5" FirstName="Hieronyma" LastName="Matti">
    <EmailAddress>Hieronyma.Matti@email.com</EmailAddress>
    <SSN>756525335</SSN>
    <Phone>150-555-0127</Phone>
  </Customer>
</Customers>

Note: The values for first and last names in your file will be different because they're chosen at random.