Strumento online di formattazione XML



suStrumento online di formattazione XML:

Questo strumento di formattazione XML online può aiutarti a formattare stringhe XML confusionarie in stringhe XML leggibili.

Questo strumento può forzare la formattazione di stringhe XML errate anche se la stringa di input non è conforme alla sintassi XML ufficiale.

I vantaggi di XML per JSON:

XML è più estensibile di JSON e XML può utilizzare tag e attributi per rappresentare relazioni complesse nei dati.

L'XML è più diffuso di JSON e la cronologia è più lunga di JSON, l'HTML è anche una specie di XML, il che significa che più persone possono comprendere i dati XML.

comic xml formatter

Altri collegamenti a XML (Extensible Markup Language):

RFC 3470 (XML): https://tools.ietf.org/html/rfc3470

XML in Python (BeautifulSoup): https://www.crummy.com/software/BeautifulSoup/

XML in Java (dom4j): https://dom4j.github.io/

Formattare stringhe XML in Python (con pacchetto 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
    

Formato stringhe XML in Java (con pacchetto 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;
}