FromXml(string)

FromXml() takes a string containing properly encoded XML and returns a table. The table maps the elements of the XML string into rows and columns.

Each row contains a single element. If the element has no child elements, then the columns in the row contains the tag name, any attribute/value pairs and the content of the tag if it is not an empty-element tag.

If the element has child elements, then the row contains the tag name and any attribute/value pairs. Child elements are placed in order in the rows below the element, in the next column to the right. This mimics the nesting and indenting used to display XML files as text.

In the image below, a simple XML example is on the left. It mimics the structure of an XML file so that structure is clearly visible. On the right is a region containing the parsed version of the XML data. You can see the formula used above the region.

GrowSE() creates a reference to the region extending from the cell labelled a in the top left, to the cell 10:2 in the bottom right. The Sum() function concatenates strings, so it is used to join the contents of all the cells together. Since XML ignores whitespace between tags, FromXML() is able to parse the output from Sum(), creating the region labelled b.

You can see how the table of parsed XML repeats the indented structure of the original and places attribute/value pairs in the same row as the element.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/0b3e324c-ce92-4ac1-baa7-ff54b4504cfe/Screenshot_2021-06-10_at_12.37.51.png

Values can be extracted from the results of FromXml() using a table comprehension. In the image below the values contained in the c elements are pulled out into a column vector.

#[ #a[R, 4] if #a[R,2] == "c"] returns the value in the 4th column (counting from 0) if the value in the 2nd column is a c for every row in #a. You can read more about table comprehensions here.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/23e0fd98-5a7d-4524-8535-bd64b920f296/Screenshot_2021-06-11_at_12.10.04.png