XML Indent - Simple Solution Here

XML Indent - Simple Solution Here

3

    Oct 14, 2005#1

    I don't think this is exactly breaking huge ground here, but it's a feature that I was sorely missing from UE - saw another post in here as well.

    Problem: Taking an "ugly" XML document (no line breaks) and making it "pretty" by indenting and putting in proper line breaks, etc.

    Solution: Set up a Tool in UltraEdit to use tidy.exe

    1) Download the HTML Tidy program from here: http://tidy.sourceforge.net/

    Make sure to get the command line version (win32, not 64-bit). The name of the zip should be tidy-exe.zip

    2) Unzip and place the tidy.exe file in your Ultra Edit directory (or anywhere else for that matter).

    3) In UE, go to Advanced > Tool Configuration. Enter the following information

    a) Command line: c:\<somepath>\tidy.exe -xml -i -m %F

    -XML tells it that it's an XML file you're delaing with
    -i tells it to indent
    -m tells it to modify the file in-place
    %F is UE's placeholder for the currently-active file

    Of course you can play around with tidy.exe and see if there are other/better options for your use.

    b) Menu Item Name: XML Tidy

    c) Command Output: Output to List Box. Everything else empty or unchecked.

    d) Press the "Insert" button to save your changes to an external tool.

    That's it. Grab an ugly XML file, go to Advanced > XML Tidy and if it worked you should get a "... has been changed by another application. Do you want to reload it?" message. Click yes and you should have a nicely indented XML file at your disposal.

    29
    Basic UserBasic User
    29

      Jun 07, 2006#2

      Would be great if one could script this as a macro:
      1) Run User Tool (XML Tidy)
      2) Reload current file
      Anyone know how?

      6,675585
      Grand MasterGrand Master
      6,675585

        Jun 08, 2006#3

        Why do you need a macro for this job?

        Run the tool with a hotkey like Ctrl+1 and press Enter at the reload dialog after the tool execution. The only advantage of a macro would be to save the Enter key press.

        The Enter key press can be also saved by selecting Automatically update changed files for File Change Detection. With this setting you do not need a macro.

        But maybe you have disabled file change detection. Then you can use the following macro:

        RunTool "XML Tidy"
        Clipboard 9
        CopyFilePath
        CloseFile
        Open "^c"
        ClearClipboard
        Clipboard 0

        XML Tidy is the case-sensitive menu item name of the tool. You will see the disadvantages of the macro. The file must be closed and reopened. So cursor position is lost and the reopened file is added to the list of open files at the end. There is no reload macro command. The better solution for this setting would be to assign a hotkey for File - Revert to Saved and after running the tool press this hotkey and Enter for reloading it.

        Although the following macro can be used also for the file change detection setting Prompt for update when files change, there are even more disadvantages as you can see. In the tool configuration, you have to replace the %F setting by "%sel%". Hopefully the Tidy.exe can also work with long filenames. And you have to disable the option Save Active File because the active file will be a new file without name during tool execution.

        Clipboard 9
        CopyFilePath
        CloseFile Save
        NewFile
        Paste
        SelectToTop
        RunTool "XML Tidy"
        CloseFile NoSave
        Open "^c"
        ClearClipboard
        Clipboard 0

        Addition: UltraEdit is installed now (v16.30) with HtmlTidy support and therefore it is not really necessary to configure a tool. There is command Format - HTML Validation - Run HTML Tidy which can be executed with a special option file instead of using the options UltraEdit offers in a dialog for HTML and XHTML files.

        And there are special XML commands like Format - XML Convert to CR/LFs or Format - XMLlint Tool.

        Last the command Format - ReIndent Selection works also well on a syntax highlighted XML file completely selected with Ctrl+A. How many tabs/spaces are used for every indentation level can be configured on a file extension base at Advanced - Configuration - Editor - Word Wrap / Tab Settings, see File extension based word wrap / tab and indent settings.
        Best regards from an UC/UE/UES for Windows user from Austria