How to indent an XML file with 2 blanks per hierarchy level?

How to indent an XML file with 2 blanks per hierarchy level?

13
Basic UserBasic User
13

    Jan 05, 2010#1

    Assume I have an XML file where every line contains NO leading blanks.

    How can I tell UE to automatically indent the lines according to their level?

    Then indention should be 2 blanks per level

    Matt

    6,681583
    Grand MasterGrand Master
    6,681583

      Jan 05, 2010#2

      First open Advanced - Configuration - Editor - Word Wrap/Tab Settings.

      Click in this configuration dialog on the button Change list...

      Type in the upper edit field xml (or XML, the case does not matter). Important is that you type the file extension without the point because the point is not part of the file extension according to Windows file name specification.

      Press the button Add and close the dialog with button OK. You are back in the configuration dialog.

      Select in the dropdown list now the entry xml. EVERYTHING below is now specific for files with the file extension XML. Important for you are now the tab configuration settings.

      Enable the setting Use spaces in place of tabs.

      Enter for Tab Stop value and also for Indent spaces the value 2.

      Close the configuration dialog with button OK. I don't know if a restart of UltraEdit is now required because I do not often change the list. For safety exit UltraEdit and restart it.

      Open your XML file. In menu Format there is the command XML Convert to CR/LFs which is designed for re-indenting valid, but not well formatted XML files. The general command ReIndent Selection in the same menu could be used also after selecting the entire file with Ctrl+A. The command XMLlint Tool calls this third-party tool (preinstalled with UltraEdit) for validation checking the XML file. And last but not least View - Views/Lists - XML Manager is a great help when working with VALID XML files.
      Best regards from an UC/UE/UES for Windows user from Austria

      13
      Basic UserBasic User
      13

        Jan 06, 2010#3

        Ok, I setup the Word Wrap/Tab Settings as you suggested.

        However NONE of the indent menus work:

        Neither XML Convert nor ReIndent Selection.
        XMLlint Tool and XML Manager seems not to exist.

        Are your solutions NOT work with (the older) UE version 12.20+1?

        Do I really have to upgrade?

        Matt

        6,681583
        Grand MasterGrand Master
        6,681583

          Jan 06, 2010#4

          Well, that you use an older version is a very important fact. Lots of XML related improvements have been implemented last year by IDM.

          Your version supports already the XMLlint Tool. The command to run it should be in the menu Format also in your version of UltraEdit when you are using the default Advanced menu profile. And the tool should exist in the GNU subdirectory in the UltraEdit program directory.

          But the XML Manager is only available with UE v15.10 and later. In the change history I found also for UE v12.20b:

          Fixed XML Convert to CR LF on very large files

          And in hotfix information for v12.20b+1:

          Fixed unclassified error running XMLLint
          Fixed reindent format option with XMLLint
          Fixed format output with XMLLint


          So it is possible that this command is not working correct for your XML file in your version of UltraEdit. XMLlint support was introduced with UE v12.10 which explains why there are some bugfixes in the following versions of UltraEdit.

          The commands ReIndent Selection as well as XML Convert to CR/LFs work only when the file is syntax highlighted with a syntax highlighting language containing the keyword XML_LANG which is by default the case with default wordfile.txt of your version of UltraEdit.

          Addition on 2011-06-03: With UE v17.10 and later the command XML Convert to CR/LFs is available for all files independent on highlighting of file with language containing keyword XML_LANG.

          For testing I opened in UE v15.20.0.1022 an XML file. Because the XML file was already perfect indented, I deleted all leading whitespaces with an UltraEdit regular expression replace all command searching for %[ ^t]+ and an empty replace string. Now I used first the command XML Convert to CR/LFs and the result was perfect. I pressed Ctrl+Z to undo the reformatting (not possible in your version of UltraEdit) and used now ReIndent Selection. Again the result was perfect.

          I unpacked from my archives also UE v12.20+1 and v12.20b+1 and tried the same as above with v15.20.0.1022 on the same XML file. And indeed both commands failed in both 12.20 versions of UltraEdit to re-indent the lines in the XML file.
          mattad wrote:Do I really have to upgrade?
          When you work in future more than up to now with XML files, you should think about it.

          But I found a workaround which worked with both UE v12.20. Selecting at View - View As (Highlighting File Type) instead of XML the language HTML, then selecting all with Ctrl+A and using ReIndent Selection worked for my example XML file. So I thought that maybe copying the lines

          /Indent Strings = "<"
          /Unindent Strings = "</"


          from the HTML syntax highlighting language in wordfile.txt to language /L6"XML" could be helpful to get the command ReIndent Selection to work for XML files as well. Indeed with those 2 lines inserted above the line

          /C1"Elements" STYLE_ELEMENT

          in wordfile.txt for language /L6"XML" helped and ReIndent Selection worked. Interesting is that default wordfile for XML in UE v15.20.0.1022 still does not contain the 2 indent/unindent strings definition lines. So IDM has really improved built-in support for XML files in later versions of UltraEdit.

          Ah, one more thing. I have seen XML files with leading non breaking spaces. A non breaking space has byte code 160 (0x80). Non breaking spaces are not interpreted as whitespaces. If you enable View - Show Spaces/Tabs and see still spaces instead of dots at start of some lines, your XML file also contains non breaking spaces. Select one of them and press Ctrl+R to open the replace dialog. The search edit field contains now already the non breaking space character. So you only have to enter a normal space in the replace edit field and press button Replace All to replace all non breaking spaces by normal spaces.

          13
          Basic UserBasic User
          13

            Jan 13, 2010#5

            It works. Perfect.
            Thank you