Mapping XPath Queries to XML File Searches

The EA parser extracts entity and relationship instances from XML using search patterns you define in Architecture Modeler. In schematic form, the parser uses these patterns to:

  • Match relationship instances in the code.
  • Form the names of entity instances:


  • Form the names of relationship instances:


Architecture Modeler's XPath query generator simplifies the task of defining these patterns. Follow the steps below to map XPath queries to XML file searches.

  1. Click the Files button in Architecture Modeler. Architecture Modeler displays the defined source file types in the Name area in the central pane of the window, and the text of the corresponding sample in the right-hand pane. If more than one source file type is listed, click the name of the type to display the sample.
  2. Define the XPath query the parser uses to match relationship instances:
    • Select the node of interest in the sample, then use the right-click menu to form the XPath query. To match the relationship OrgChartDefinesOrgChartEmployee in the XML code shown below, the XPath query would be:
      /def:OrgChart/def:Employees/child::def:Employee

      To form the query, select the <Employees> node and choose Select All <Employees> children elements > /child::def:Employee from the right-click menu.

    • The XPath query is displayed in the XPath Query field. When you are satisfied with the query, click Pick.


    The Add Expression window opens.
  3. Enter an expression ID, e.g. "employee" for the selected Employees xml element. All expression IDs are displayed in a tree on the middle-bottom left-hand side of the screen in.
  4. Select the expression ID and choose Edit from the right-click menu. The Edit XPath Mapping window opens. The XPath Query for the matched relationship is displayed in the XPath Main Query field.
  5. In the right-hand pane of the Edit XPath Mapping window, define the XPath query the parser uses to form the names of entity instances. You do not need to define a query for the source file name:
    • In the Entity group box, select the entity type you want to match in the Type drop-down, ORGCHARTEMPLOYEE in our example.
    • Use a subexpression of the XPath query you created in step 2 to match an attribute of the node. If you want to form the entity name from the Name attribute, enter %./@name% in the cell beside the Name attribute. That subexpression matches the employees "John Doe," "Ivan Ivanov," and "John Smith" in our example. If you are matching a different attribute, title, for example, enter %./@title% in the cell next to the Name attribute.
    • Assuming you are defining a relationship between a source file and an extracted object, enter the system variable %[ExpressionID].sourcefilename% in the cell beside the Source attribute. If you are defining another type of relationship, reference-resolving information may be contained in a different attribute.
  6. Click Save in the Entity group box. The entity mapping is added to the list of mappings in the Mapping List group box. Repeat this procedure for each entity mapping you want to define. The figure below shows the entity mapping for our example.


  7. In the right-hand pane of the Edit XPath Mapping window, define the XPath query the parser uses to form the names of relationship instances:
    • From the Type drop-down in the Relation group box, select the relationship type you want to map, OrgChartDefinesOrgChartEmployee in our example.
    • Map the subexpression for the left entity name. If you formed the entity name from the name attribute of the node, enter %./@name% in the cell next to the Left Entity Name attribute. If you are defining a relationship between a source file and an extracted object, enter the system variable %[ExpressionID].sourcefilename% in the cell next to the Left Entity Name attribute.
    • Map the subexpression for the right entity name. If you formed the entity name from the name attribute of the node, enter %./@name% in the cell beside the Right Entity Name attribute.
  8. Click Save in the Relation group box. The relationship mapping is added to the list of mappings in the Mapping List group box. The figure below shows the relationship mapping for our example.
    Note: To edit a mapping definition, select it in the Mapping List group box and click Edit. Follow the procedure you used to define the mapping. To delete a mapping definition, select it in the Mapping List group box and click Remove.


  9. When you are satisfied with your entries in the Edit XPath Mapping window, click Save.
Architecture Modeler displays the search pattern for the matched relationship in the Match pattern area in the central pane of the window.
Note: Select the search pattern for the matched relationship and choose Edit in the right-click menu to modify the pattern. Select it and choose Delete from the right-click menu to delete the pattern.