1.

Solve : Writing an XML code beautifier?

Answer»

Here's the IDEA....

Given an input string containing XML data, without any indentation, output a string of XML with proper indentation.

Example:

Input string:
Code: [Select]<collection><book id="1"><title>Charlie and the Chocolate Factory</title></book><book id="2"><title>C, How to Program</title</book></collection>
Output string:
Code: [Select]<collection>
    <book id="1">
        <title>Charlie and the Chocolate Factory</title>
    </book>
    <book id="2">
        <title>C, How to Program</title
    </book>
</collection>

I've never tried to tackle ANYTHING like this before, so any help is appreciated. I just need a starting point. Think about how you WOULD do it by hand and mimic that process in your code. Start with an indent of zero and add to it every time you encounter an opening tag and subtract every time you encounter a closing one.

Ya, that's what I have kind of started to do. Thanks for the reply  I'm not that good with xml myself but i can get by using an xml editor, try using Liquid XML Editor as it has syntax highlighting, auto code COMPLETION, xml validation ETC etc



Discussion

No Comment Found