The OneStream Community is temporarily frozen until June 29th due to the ongoing maintenance. Please read the blog post here to learn more.
Forum Discussion
MarcusH
2 years agoValued Contributor
Format of XML files in Application extract zip file
Does anyone know if it is possible to format the XML files that are created by the application extract. In particular I want to format the Metadata extract so that there is a single line for the memb...
- 2 years ago
I get what you're doing. It makes sense. However, Git has the ability to track this without needing to mangle the XML. in VS you can open your xml in a diff to see the individual changes. Its built in. 🙂
JackLacava
OneStream Employee
2 years agoComparing xmls by relying on text-formatting rules is the wrong approach; you want a dedicated tool, like https://xmldiff.readthedocs.io/. There are other options, like the ones https://superuser.com/questions/79920/how-can-i-diff-two-xml-files.
- MarcusH2 years agoValued Contributor
Hi Jack
Thanks for the reply. I have already written a script for comparing XML files. It's cumbersome and I was wondering if there was a better way. It's the format that OS produces the file in eg there's a setting somewhere in the API that controls the XML output. It would make Git much simpler.
- RobbSalzmann2 years agoValued Contributor II
Unfortunately, there's no "setting" controlling XML output specific to the formatting of indicated tags. Its the nature of the XDocument library to output human formatted XML. As an experiment you can literally "flatten" each member tag section using a regex and add it back to the XDocument object. Upon writing that document back to a file, you will find your previously flattened xml all nicely formatted again.
public static void XdocumentFormatExperiment(string inputFilePath, string outputFilePath) { XDocument doc = XDocument.Load(inputFilePath); foreach (var member in doc.Descendants("member").ToList()) { // Convert the member element and its children to a single line string string memberAsString = member.ToString(); string singleLineMember = Regex.Replace(memberAsString, @"\r\n?|\n", ""); singleLineMember = Regex.Replace(singleLineMember, @">\s*<", "><"); Console.WriteLine(singleLineMember); // all nicely flattened on one line... // replace the original <member tag with the flattened one member.ReplaceWith(XElement.Parse(singleLineMember)); } //write out the new xml doc with the flattened member tags // open the file and find they're all formatted again. doc.Save(outputFilePath); }
Related Content
- 4 years ago
- 2 years ago