XML Formatter Online Tool
About XML Formatter Online Tool:
This online xml formatter tool helps you to format raw XML string so it can easily be read by human being.
This tool can force to format invalid XML String, even if the input String doesn't comply the official XML syntax properly.
Basic idea of XML:
XML is a data format specification, a format specification that contains data and data descriptions.
For example: We want to send a piece of data to the other party, the data content is "too young too simple sometimes naive"
, if you want to split this paragraph into three data according to the attribute, that is, age
: too young; experience
: too simple; result
: sometimes naive.
For human the expression is "too young,too simple,sometimes naive", Information is split by comma, the first part is the age
, the second part is the experience
, and the third part is the result
. This method can be used to hold data and can be parsed, but it is not intuitive, and the versatility is not good. If there is a string that exceeds the limit of the number of words, it can not be parsed, and the data itself may contain comma!!!
We all know that programs are not like people, we can understand the literal meaning, and automatically split the data, so we need to help the program to do the split, so there are a variety of data formats and split methods.
To address this problem, XML is invented, and the above data is expressed in XML can be like this
<person age="too young" experience="too simple" result="sometimes naive" />
or like this:
<person> <age value="too young" /> <experience value="too simple" /> <result value="sometimes naive" /> </person>
even like this:
<person age="too young" experience="too simple"> <result value="sometimes naive" /> </person>
ALl above XML intuitively describe the data, and they are common format specification for the program to parse.
What is the XML namespace? Why is it important?
The XML namespace is similar to Java's package to avoid conflicts between tags with the same source name. The XML namespace is defined at the top of the XML document using the xmlns attribute with the syntax xmlns:prefix='URI'. Prefix isused with the actual label in the XML document. The following example shows the use of an XML namespace.
<root xmlns:article="https://wordpress.org/post"> <post> <article:title>How to ensure the effectiveness of MOOC learning</article:title> <article:date>March 25, 2019</article:date> </post> </root>
The Advantages of XML over JSON:
XML is more extensible than JSON, XML can use tags and attributes to represent complex relationships within data.
XML is more widely used than JSON and has a longer history than JSON, HTML is also a kind of XML. It means XML data can be understand by more programmers.
Does XML Formatter Online Tool log my data?
Absolutely NOT, this XML Formatter doing all the formatting work on the client side, all logic are implemented by Javascript. There are 2 major advantages: 1.Your data never transmitted in the Open Internet, so you know it's secure; 2.It's much faster than doing all the work in the server side, because there is no Internet Delay.
More information about XML (Extensible Markup Language):
RFC 3470 (XML): https://tools.ietf.org/html/rfc3470
Python Implementation of XML (BeautifulSoup): https://www.crummy.com/software/BeautifulSoup/
Java Implementation of XML (dom4j): https://dom4j.github.io/
XML Formatter with Python (with package xml.dom):
from xml.dom import minidom def format_xml(input_str): str = minidom.parseString(input_str) output_str = str.toprettyxml(indent=" ") return output_str
XML Formatter with Java (with package dom4j):
import org.dom4j.Document; import org.dom4j.DocumentHelper; import org.dom4j.io.OutputFormat; import org.dom4j.io.XMLWriter; public String Format(String xmlStr){ Document document=DocumentHelper.parseText(xmlStr); OutputFormat format=OutputFormat.createPrettyPrint(); format.setIndentSize(4); StringWriter stringWriter=new StringWriter(); XMLWriter writer=new XMLWriter(stringWriter,format); writer.write(document); String resultStr=stringWriter.toString(); return resultStr; }