Products
  
  
  Crash Magic Online
  
  Intersection Magic
  
  Map Magic
  
  Knowledge Base
  
  
  
  Contact Us
  
  Meeting
  
  Shop
  
  Login
  

 

Knowledge Base Article:CMO291 


Registration keys moved to client area: Select login on the left menu bar.

Knowldegebase:
Search home page  

Formatting XML

Article created: Mar 28 2015, updated: Mar 28 2015

Background:  In order to read and/or compare XML files it can be handy to format them in a common way.  This article describes one method for doing this.  It relies on a free 3rd party product that needs to be downloaded first.

Status:  Info - "how to" article
Keywords:  
Categories:   *Configuration* *Importing* *Data* *Article - references*

Explanation:

XML files are read by programs using an XML "parser".  A proper XML parser will ignore all whitespace, tabs, line feeds, etc. in an XML document.  This means that when producing XML, a program may choose to format the xml in many ways, or even to omit formatting alltogether.

The good news is that properly constructed XML can be re-formatted quite easily with the right software.  There are many editors available that can do this. (we like Notepad++ with the XML Tools plug-in)  However, in order to "clean" lots of files, as in hundreds or thousands at a time, this becomes impractical. 




Solution:

Steps to clean a folder full of XML files.

  1. There exists a utility called XMLStarlet at http://xmlstar.sourceforge.net/ that we use to process folders.  Download this and put the xml.exe in a folder that is in your system path. (Pd' Programming employees - this utility is located on your U: drive)
  2. Hint: When using Windows Explorer to navigate your hard disk, you can enter "cmd" into the path edit (at the top of the window) to open a command prompt at that folder location.
  3. To process all files "in place", losing the original content and replacing it with newly formatted content, execute this command from within the folder containing the xml files:
    for %f in (*.xml) do (ren %f x_%f & xml.exe fo --indent-spaces 1 --omit-decl --omit-decl x_%f > %f & del x_%f)
  4. To create new files in a subdirectory called "formatted", create that directory and then execute this command from within the folder containing the xml files:
    for %f in (*.xml) do (xml.exe fo --indent-spaces 1 --omit-decl --omit-decl %f > formatted\%f)

September 18, 2018 7:18PM

© 1999-2018 Pd' Programming, Inc - Lafayette, CO USA