Forum Discussion
Skip parsing blank XML
Once you have the data ingested what is the next step - what are you planning to do with it? Is this a one-off report, or do you want to share that semantic model with others? Have you considered normalizing the data?
I need to get all that XML data into SQL server so other teams can access it. I'll also be using it for some analyses and visualizations. The data in the XML are already kind of "flat," so I'm not sure normalizing would provide any benefit.
- lbendlin1 year agoSuper User
The XML data is the furthest from "flat" that you can get. It has dozens of hierarchy layers in dozens of different branches. As you said , it is way more complex than any examples you will find online.
Here's my proposal on how to start the normalization:
Header: let Source = Xml.Tables(File.Contents("C:\Users\xxx\Downloads\text.xml")), Table = Source{0}[Table], Table1 = Table{0}[Table], #"Expanded CJISQueryRequester" = Table.ExpandTableColumn(Table1, "CJISQueryRequester", {"PersonFullName"}, {"CJISQueryRequester"}), #"Expanded CJISQueryOperator" = Table.ExpandTableColumn(#"Expanded CJISQueryRequester", "CJISQueryOperator", {"PersonFullName"}, {"CJISQueryOperator"}), #"Expanded CJISQueryAuthorizer" = Table.ExpandTableColumn(#"Expanded CJISQueryOperator", "CJISQueryAuthorizer", {"PersonFullName"}, {"CJISQueryAuthorizer"}), #"Expanded CJISUserID" = Table.ExpandTableColumn(#"Expanded CJISQueryAuthorizer", "CJISUserID", {"ID"}, {"CJISUserID"}), #"Expanded OrganizationORIID" = Table.ExpandTableColumn(#"Expanded CJISUserID", "OrganizationORIID", {"ID"}, {"OrganizationORIID"}) in #"Expanded OrganizationORIID" Paystation: let Source = Xml.Tables(File.Contents("C:\Users\xxx\Downloads\text.xml")), Table = Source{0}[Table], Table1 = Table{1}[Table], Table2 = Table1{0}[Table], Table3 = Table2{0}[Table], DataElements = Table3{0}[DataElements], DataElement = DataElements{0}[DataElement], #"Expanded http://www.xfact.com/schemas/eopss/dot-ec/1.0/extension" = Table.ExpandTableColumn(DataElement, "http://www.xfact.com/schemas/eopss/dot-ec/1.0/extension", {"Attribute:elementName"}, {"Attribute:elementName"}), #"Pivoted Column" = Table.Pivot(#"Expanded http://www.xfact.com/schemas/eopss/dot-ec/1.0/extension", List.Distinct(#"Expanded http://www.xfact.com/schemas/eopss/dot-ec/1.0/extension"[#"Attribute:elementName"]), "Attribute:elementName", "Element:Text") in #"Pivoted Column" ECitation: let Source = Xml.Tables(File.Contents("C:\Users\xxx\Downloads\text.xml")), Table = Source{0}[Table], Table1 = Table{1}[Table], Table2 = Table1{0}[Table], Table3 = Table2{1}[Table] in Table3The ECitation object alone is far, far more complex than what you would normally attempt to flatten. I'd say anything beyond four levels of hierarchy is very very ambitious.
- johnjbolduc1 year agoHelper II
Thanks, but your example assumes reading the XML from a file. My XML is in a SQL Server database column.
I'm guessing what I want to do isn't really doable given the complexity and volume of data.
- lbendlin1 year agoSuper User
I would go back to SQL views that parse the XML directly, and I would do separate views that focus on the individual parts. Then you can use Power BI to bring at least some resemblance of a data model into play.
- johnjbolduc1 year agoHelper II
I started out trying to do all this in SQL using XQUERY but got nowhere at all. I was actually able to use string functions in my SQL to parse out the pieces, and it works fine, but the performance is horrendous.
- lbendlin1 year agoSuper User
What's the "make and model" of your SQL Server? Do you know the db admin?
- johnjbolduc1 year agoHelper II
And SSMS v20.
- lbendlin1 year agoSuper User
SQL Server 2012 ? I'm impressed that this thing is still alive. See if you can negotiate an update to something a little more contemporary - newer version have much better XML support.
- johnjbolduc1 year agoHelper II
I'm just a contractor for Commonwealth of Massachusetts; there's no way I can make that happen.
- lbendlin1 year agoSuper User
I figured as much. Make sure to manage your client's expectations.
Greetings from around the block.
- johnjbolduc1 year agoHelper II
Thanks so much!
- Anonymous1 year agoNot applicable
Hi johnjbolduc
Did the solution lbendlin offered help you solve the problem, if it helps you can consider to acceot it as a solutio so that more user can refer to.
Best Regards!
Yolo Zhu
- johnjbolduc1 year agoHelper II
Unfortunately, no. My XML is much too complicated for anything offered here.