How do I format XML in Notepad++?

后端 未结 20 2461
不思量自难忘°
不思量自难忘° 2020-11-27 08:40

I have Notepad++ and I got some XML code which is very long. When I pasted it in Notepad++ there was a long line of code (difficult to read and work with).

I want to

相关标签:
20条回答
  • 2020-11-27 09:17

    You can't, granted you don't have access to install plugins. But you probably have or can get Eclipse (Visual Studio can do this too).

    Ctrl + N (new file) → (choose XML file) → (paste your XML content) → Ctrl + Shift + K (format)

    If you want to format JSON NotePad++ can do this by default with Ctrl + Alt + m

    0 讨论(0)
  • 2020-11-27 09:19

    You need to install the XML tool from the Plugins menu item → Plugins Admin...Plugins Admin dialog appears and then scroll to bottom of available plugins and check the XML tools, install it and then Ctrl + Alt + Shift + B OR the option for XML Tool above shows up.

    0 讨论(0)
  • 2020-11-27 09:20

    OK, here is how I did it in Notepad++:

    • Plugins
    • Plugin manager
    • Show plugin manager
    • Check XML tools
    • Install
    • Restart Notepad++
    • Open XML file
    • Plugins
    • XML tools
    • Pretty print (XML only -- with line breaks)
    0 讨论(0)
  • 2020-11-27 09:22

    Try Plugins -> XML Tools -> Pretty Print (libXML) or (XML only - with line breaks Ctrl + Alt + Shift + B)

    You may need to install XML Tools using your plugin manager in order to get this option in your menu.

    In my experience, libXML gives nice output but only if the file is 100% correctly formed.

    0 讨论(0)
  • 2020-11-27 09:23

    UniversalIndentGUI did the job for me, once configured properly as described above.

    TextFX would not install and run correctly on an old PC I have running Windows XP. There are instructions above for manual installation of various DLL files, but I'd rather avoid any manual installation.

    UniversalIndentGUI formatted some lines like this:

            <ClockStatus>1
            </ClockStatus>
    

    And I would have preferred:

            <ClockStatus>1</ClockStatus>
    

    But the output is still much better than one long line!

    0 讨论(0)
  • 2020-11-27 09:24

    For best results, you should use both TextFX XML tidy and XML tools pretty print. Here's how and why:

    1.TextFX -> TextFX HTML Tidy -> Tidy: reindent XML
    

    TextFX has the benefit of wrapping long lines, which XML Tools does not do, but it doesn't indent those new lines correctly.

    2. XML Tools -> Pretty print (Text indent)
    

    XML Tools complements TextFX by indenting the newly wrapped lines nicely.

    0 讨论(0)
提交回复
热议问题