• Skip to main content
  • Skip to primary sidebar
  • Skip to footer

bVisual

  • Home
  • Services
    • How Visio smartness can help your business
    • Visio visual in Power BI
    • Visio Consulting Services
    • Visio Bureau Services
    • Visio Training and Support Services
  • Products
    • Visio Shape Report Converter
    • SS Plus
    • LayerManager
    • visViewer
    • Metro Icons
    • Rules Tools for Visio
    • The Visio 2010 Sessions App
    • Multi-Language Text for Visio
    • Document Imager for Visio
    • multiSelect for Visio
    • pdSelect for Visio
  • Case Studies
    • Case studies overview
    • Using Visio in Education for GIS
    • Visualizing Construction Project Schedules
    • Visio Online Business Process Mapping
    • Nexans Visio Template
    • CNEE Projects, WorldCom
    • Chase Manhattan Bank
  • News
    • Recent news
    • News archive
  • Resources
    • Articles➡
      • ShapeSheet Functions A-Z
      • Comparing Visio for the Web and Desktop
      • Customising Visio Shapes for the Web App
      • Key differences between the Visio desktop and web apps
      • Using the Visio Data Visualizer in Excel
      • Using Visio in Teams
      • Creating Visio Tabs and Apps for Teams with SharePoint Framework (SPFx)
      • Designing Power Automate Flows with Microsoft Visio
      • Innovative uses of Visio Lists
    • Webcasts ➡
      • Visio in Organizations
      • My session and other Visio sessions at MSIgnite 2019
      • Power up your Visio diagrams
      • Vision up your Visio diagrams
      • The Visio 2010 MVP Sessions
    • Visio Web Learning Resources
    • Books➡
      • Visualize Complex Processes with Microsoft Visio
      • Mastering Data Visualization with Microsoft Visio
      • Microsoft Visio Business Process Diagramming and Validation
      • Visualizing Information with Microsoft Visio
  • Blog
    • Browse blog articles
    • Visio Power BI articles
    • Visio for Web articles
    • A history of messaging and encryption
  • About us
    • About bVisual
    • Testimonials
    • Bio of David Parker
    • Contact Us
    • Website Privacy Policy
    • Website terms and conditions
    • Ariba Network
You are here: Home / Shape Design / ShapeSheet Formulas / More Parsing XML Data in Visio Shapes

Published on July 14, 2023 by David Parker

More Parsing XML Data in Visio Shapes

My last article looked at parsing an XML string with a known structure and order of elements and attributes. This can be acceptable in some scenarios, but what if the elements or attributes are in a different order? Then it is necessary to use the element and attribute names rather than their index position. This requires a little more complexity to the ShapeSheet functions, and this can result in longer processing time, so needs to be used cautiously, but it is possible, as I demonstrate in this article.

  • Books group shape contains 20 child book shapes
  • Main functions in the document ShapeSheet
  • Called from cells in the group shape
  • Child shapes call functions in the parent shape

The Document ShapeSheet functions

I reduced the main ShapeSheeet functions to just four, for my purpose, and placed them in the User-defined Cells section of the document ShapeSheet. They can then be used by any shape within the document.

fnGetElement

Function to get the named ELEMENT within provided xml NODE

=IFERROR(
IF(
FIND("<"&ARG("ELEMENT")&">",ARG("NODE"),1,TRUE)>0,
MID(ARG("NODE"),
FIND("<"&ARG("ELEMENT")&">",ARG("NODE"),1,TRUE)+
LEN("<"&ARG("ELEMENT")&">"),
FIND("</"&ARG("ELEMENT")&">",ARG("NODE"),1,TRUE)-
LEN("<"&ARG("ELEMENT")&">")-
FIND("<"&ARG("ELEMENT")&">",ARG("NODE"),1,TRUE)),
MID(ARG("NODE"),
FIND(">",ARG("NODE"),
FIND("<"&ARG("ELEMENT")&" ",ARG("NODE"),1,TRUE))+1,
FIND("</"&ARG("ELEMENT")&">",ARG("NODE"),1,TRUE)-
FIND(">",ARG("NODE"),
FIND("<"&ARG("ELEMENT")&" ",ARG("NODE"),1,TRUE)
,1,TRUE)))
,"")

The FIND(…) function has an optional argument to be case insensitive, and the IFERROR(…) function provides the ability to return an empty string if the FIND(…) fails.

fnGetAttribute

Function to get the named ATTRIB within provided xml NODE

=IFERROR(
IF(
OR(LEN(ARG("ELEMENT"))=0,LEN(ARG("ATTRIB"))=0),
"",
MID(ARG("ELEMENT"),
FIND(" "&ARG("ATTRIB")&"=""",ARG("ELEMENT"),1,TRUE)+
LEN(" "&ARG("ATTRIB")&"="""),
FIND("""",ARG("ELEMENT"),
FIND(" "&ARG("ATTRIB")&"=""",ARG("ELEMENT"),1,TRUE)+
LEN(" "&ARG("ATTRIB")&"=""")+1,TRUE)-
FIND(" "&ARG("ATTRIB")&"=""",ARG("ELEMENT"),1,TRUE)-
LEN(" "&ARG("ATTRIB")&"=""")))
,"")

fnGetElementCount

Function to get the count of the named ELEMENTs within provided xml NODE

=(
LEN(ARG("NODE"))-
LEN(SUBSTITUTE(LOWER(ARG("NODE")),"</"&LOWER(ARG("ELEMENT"))&">",""))
)/
LEN("</"&LOWER(ARG("ELEMENT"))&">")

fnGetElementAtIndex

Function to get the named ELEMENT at index position IDX within provided xml NODE

=IFERROR(
INDEX(ARG("IDX"),
ARG("NODE"),"</"&
ARG("ELEMENT")&">",
REF())&
"</"&ARG("ELEMENT")&">",
"")

The Books master shape

The Books master shape references these functions, and has a Shape Data row, Xml, which can have a suitable XML string pasted into it, either via the Shape Data window or using the ScreenTip dialog. The ScreenTip dialog is the only native window in Visio that provides a multi-line display and has been linked to Prop.Xml with the following SETATREF(…) formula.

=SETATREF(Prop.Xml)

The Books shape also has an extra User-defined Cell, User.ElementCount, returns the number of book elements in the catalog node, used for visibility of each sub-shape:

=EVALCELL(User.fnGetElementCount,"NODE",LOWER(EVALCELL(User.fnGetElement,"ELEMENT",LOWER("catalog"),"NODE",Prop.Xml)),"ELEMENT",LOWER("book"))

The remaining User-defined Cell, User.MaxIndex, contains a formula that is used in the sub-shapes

The book sub-shapes

Each of the 20 sub-shapes have a Prop.Index Shape Data row which has a unique value from 0 to 19 to provide an index into each of the book child elements of the catalog node in the Prop.Xml string of the parent shape. This Prop.Index value is the only cell that needs to be edited when a sub-shape is duplicated. The other ShapeSheet cells automatically evaluate from this value.

The Geometry1.NoShow cell formula simply returns TRUE if the Prop.Index value is greater than the number of book elements in the catalog node.

=GUARD(Prop.Index>=Sheet.5!User.ElementCount)

Each sub-shape represents a book, at the unique, sequential Prop.Index value child book element of the catalog node in the Xml string. There are 20 sub-shapes in my Books shape, which is therefore the maximum number of books that can be displayed. If there are less than 20 book elements in the catalog node, then the indexed sub-shape is automatically zero width and is invisible.
The Width cell formula of each sub-shape simply divides the Width of the Books shape by the number of book elements with a limit of the number of indices I have entered in the Prop.Index.Format cell. Of course, the Width is zero if there is no book element at the Prop.Index value position:

=GUARD(IF(Geometry1.NoShow,0,Sheet.5!Width*1/MIN(Sheet.5!User.ElementCount,LEN(Prop.Index.Format)-LEN(SUBSTITUTE(Prop.Index.Format,";","")))))

The text and the ScreenTip (Comment cell) are evaluated with a formula similar to this:

=EVALCELL(Sheet.5!User.fnGetElement,
"ELEMENT","title",
"NODE",EVALCELL(Sheet.5!User.fnGetElementAtIndex,
"IDX",Prop.Index,
"ELEMENT","book",
"NODE",EVALCELL(Sheet.5!User.fnGetElement,
"ELEMENT","catalog",
"NODE",Sheet.5!Prop.Xml)
)
)

Only the first ELEMENT argument, title in the above example, needs to be changed to get a different child element value of the indexed book element.

Example Xml

<?xml version="1.0"?>
<catalog>
   <book id="bk101">
      <author>Gambardella, Matthew</author>
      <title>XML Developer's Guide</title>
      <genre>Computer</genre>
      <price>44.95</price>
      <publish_date>2000-10-01</publish_date>
      <description>An in-depth look at creating applications 
      with XML.</description>
   </book>
   <book id="bk102">
      <author>Ralls, Kim</author>
      <title>Midnight Rain</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2000-12-16</publish_date>
      <description>A former architect battles corporate zombies, 
      an evil sorceress, and her own childhood to become queen 
      of the world.</description>
   </book>
</catalog>

Example document

Related articles

Fixing dimensions of 2D shapes

I am often asked what makes Visio unique and makes it stand out from the crowd, especially in today’s online world. Well, I think there are many reasons, but one of them is the ability to create scaled drawings with parametric components of specific dimensions. This was crucial for my adoption of Visio back in…

Smart Radio Buttons and Check Boxes in Visio

A recent project requires an interactive tutorial within Microsoft Visio desktop where a lot of the questions need a single answer using radio buttons, or multiple-choice answers using check boxes. I thought that this would be a great use of the list containers capability because the questions and answers could be part of the container…

Using Button Face Ids in Visio

Microsoft Visio desktop has the ability to display icons from a built-in list of Office icons on Actions and Action Tags (nee Smart Tags). These can be set in the ShapeSheet by using the desired number from several thousand in the ButtonFace cell. Although there is the ability to add better icons using code, the…

Grid Snapping Revisited

I have previously tackled the subject of snapping to grids in Visio desktop (see https://bvisual.net/2018/06/19/really-snapping-to-grids-in-visio/ ) but a recent project required me to improve the example because it did not respond to all cursor arrow keys. The problem was that the previous solution could not understand which arrow key had been clicked, therefore it did…

Synchronizing Visio Shape Fill Color (or almost any cell) across pages

I was recently asked how the color of one shape can be changed and for other shapes to be automatically updated to the same color … even if they are on different pages! Well, it is possible with Microsoft Visio’s awesome ShapeSheet formulas. In fact, this capability is not limited to the FillForegnd cell ……

Positioning Visio Shape Text Block with a Control Handle

I was recently asked how a control handle can be added to a Visio shape so that it can be used to re-position the text block. Fortunately, it is extremely easy to setup, and requires just two formulas to be updated in the ShapeSheet. This is a great use of the SETATREF(…) function. (more…)

Related

Filed Under: Shape Data, ShapeSheet Formulas, Visio Tagged With: ShapeSheet Functions, Visio, Xml

About David Parker

David Parker has 25 years' experience of providing data visualization solutions to companies around the globe. He is a Microsoft MVP and Visio expert.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

  • LinkedIn
  • Twitter

Recent Posts

  • Fixing dimensions of 2D shapes
  • Merging Linked Data from Similar Tables
  • Smart Radio Buttons and Check Boxes in Visio
  • Using Button Face Ids in Visio
  • Grid Snapping Revisited

Categories

Tags

Accessibility Add-Ins Connectors Containers Data Export Data Graphics Data Import Data Visualizer Educational Excel GraphDatabase Hyperlinks Icon Sets JavaScript LayerManager Layers Legend Link Data to Shapes Lists MSIgnite MVP Office365 Org Chart PowerApps PowerBI PowerQuery Processes Setup and Deployment Shape Data Shape Design ShapeSheet ShapeSheet Functions SharePoint 2013 SQL Teams Validation VBA Video Visio Visio 2007 Visio for the Web Visio Online Visio Services Visio Viewer Webinar

Footer

bVisual Profile

The UK-based independent Visio consultancy with a worldwide reach. We have over 25 years experience of providing data visualization solutions to companies around the globe.

Learn more about bVisual

  • Amazon
  • E-mail
  • Facebook
  • LinkedIn
  • Twitter
  • YouTube

Search this website

Recent posts

  • Fixing dimensions of 2D shapes
  • Merging Linked Data from Similar Tables
  • Smart Radio Buttons and Check Boxes in Visio
  • Using Button Face Ids in Visio
  • Grid Snapping Revisited

Copyright © 2025 · Executive Pro on Genesis Framework · WordPress · Log in