XML Tools
Format, validate, minify, and convert XML data with XPath support
Essential for working with SOAP APIs, configuration files, and structured documents. Our XML tools help you format, validate, and query XML documents using XPath. Perfect for developers working with web services, RSS feeds, SVG graphics, or enterprise data exchange formats.
Format & Minify XML
Pretty print or minify your XML data with customizable formatting options
What is XML?
XML (eXtensible Markup Language) is a markup language designed to store and transport data in a format that is both human-readable and machine-readable. Created by the W3C (World Wide Web Consortium) in 1996, XML was derived from SGML (Standard Generalized Markup Language) to be simpler and more suitable for web use.
History & Creation
XML 1.0 was published as a W3C Recommendation on February 10, 1998. It was designed by a working group led by Jon Bosak of Sun Microsystems, with contributions from Tim Bray, Jean Paoli, C. M. Sperberg-McQueen, and others. The goal was to create a simplified version of SGML for the web.
Where XML is Used
- SOAP web services and APIs
- Configuration files (pom.xml, web.xml)
- RSS and Atom feeds
- SVG graphics and XHTML
- Office documents (DOCX, XLSX)
- Android layouts and resources
- AJAX data exchange
Benefits Over Other Formats
- vs JSON: Schema validation, namespaces, attributes, comments, CDATA sections
- vs CSV: Hierarchical structure, mixed content, metadata via attributes
- vs Binary: Human-readable, self-documenting, platform-independent
- vs HTML: Strict syntax rules, custom tags, data-focused rather than display
Working with XML Across Operating Systems
🪟 Windows
- Notepad++ with XML Tools plugin
- Visual Studio/VS Code for editing
- PowerShell XML cmdlets
- MSXML parser built-in
🍎 macOS
- xmllint command-line tool
- BBEdit or VS Code editors
- plutil for plist XML files
- LibXML2 pre-installed
🐧 Linux
- xmlstarlet for CLI processing
- vim/emacs with XML modes
- xsltproc for transformations
- xmllint for validation
XML Structure Examples & Best Practices
XML provides powerful features for structuring data with validation, namespaces, and semantic markup. Here are comprehensive examples demonstrating various patterns.
Basic XML Structures
Simple XML Document
Basic XML structure with declaration, root element, and nested elements
<?xml version="1.0" encoding="UTF-8"?>
<person>
<firstName>John</firstName>
<lastName>Doe</lastName>
<age>30</age>
<email>john.doe@example.com</email>
<address>
<street>123 Main St</street>
<city>New York</city>
<state>NY</state>
<zipCode>10001</zipCode>
</address>
</person>
XML with Attributes
Using attributes for metadata and element properties
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<product id="1001" category="electronics" inStock="true">
<name>Laptop</name>
<brand>TechCorp</brand>
<price currency="USD">999.99</price>
<specs>
<ram unit="GB">16</ram>
<storage unit="TB" type="SSD">1</storage>
<display size="15.6" resolution="1920x1080"/>
</specs>
</product>
<product id="1002" category="electronics" inStock="false">
<name>Smartphone</name>
<brand>PhoneCo</brand>
<price currency="USD">699.99</price>
</product>
</catalog>
Namespaces and Schemas
XML with Namespaces
Using namespaces to avoid element name conflicts
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:order="http://example.com/order"
xmlns:customer="http://example.com/customer">
<order:order orderID="12345">
<order:date>2024-01-20</order:date>
<order:total currency="USD">150.00</order:total>
<customer:customer customerID="67890">
<customer:name>Jane Smith</customer:name>
<customer:email>jane@example.com</customer:email>
</customer:customer>
<order:items>
<order:item sku="ABC123" quantity="2">
<order:description>Widget</order:description>
<order:price>75.00</order:price>
</order:item>
</order:items>
</order:order>
</root>
XML Schema (XSD) Definition
Schema for validating XML structure and data types
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="employee">
<xs:complexType>
<xs:sequence>
<xs:element name="firstName" type="xs:string"/>
<xs:element name="lastName" type="xs:string"/>
<xs:element name="employeeId" type="xs:positiveInteger"/>
<xs:element name="department">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Engineering"/>
<xs:enumeration value="Sales"/>
<xs:enumeration value="Marketing"/>
<xs:enumeration value="HR"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="salary" type="xs:decimal"/>
<xs:element name="startDate" type="xs:date"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
SOAP Web Service Example
SOAP Request
SOAP envelope for web service communication
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ws="http://example.com/webservice">
<soap:Header>
<ws:Authentication>
<ws:Username>john_doe</ws:Username>
<ws:Password>secure_password</ws:Password>
</ws:Authentication>
</soap:Header>
<soap:Body>
<ws:GetUserInfo>
<ws:UserId>12345</ws:UserId>
<ws:IncludeDetails>true</ws:IncludeDetails>
</ws:GetUserInfo>
</soap:Body>
</soap:Envelope>
SOAP Response
SOAP response with user data
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ws="http://example.com/webservice">
<soap:Body>
<ws:GetUserInfoResponse>
<ws:User>
<ws:UserId>12345</ws:UserId>
<ws:Username>john_doe</ws:Username>
<ws:Email>john@example.com</ws:Email>
<ws:RegisteredDate>2023-01-15</ws:RegisteredDate>
<ws:Status>Active</ws:Status>
</ws:User>
</ws:GetUserInfoResponse>
</soap:Body>
</soap:Envelope>
Configuration Files
Maven POM.xml
Java project configuration file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>my-app</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
RSS Feed Example
RSS 2.0 Feed
Blog or news feed structure
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
<title>Tech Blog</title>
<link>https://example.com/blog</link>
<description>Latest technology news and tutorials</description>
<language>en-us</language>
<pubDate>Sat, 20 Jan 2024 12:00:00 GMT</pubDate>
<item>
<title>Understanding XML in Modern Web Development</title>
<link>https://example.com/blog/xml-modern-web</link>
<description>A comprehensive guide to using XML effectively...</description>
<author>jane@example.com (Jane Smith)</author>
<category>Web Development</category>
<guid isPermaLink="true">https://example.com/blog/xml-modern-web</guid>
<pubDate>Sat, 20 Jan 2024 10:00:00 GMT</pubDate>
<content:encoded><![CDATA[
<p>XML continues to play a crucial role in modern web development...</p>
<p>In this article, we'll explore practical applications...</p>
]]></content:encoded>
</item>
</channel>
</rss>
Android Layout XML
Android UI Layout
Mobile app interface definition
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:id="@+id/titleText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome"
android:textSize="24sp"
android:textStyle="bold"
android:layout_marginBottom="16dp"/>
<EditText
android:id="@+id/usernameInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username"
android:inputType="text"/>
<EditText
android:id="@+id/passwordInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"
android:layout_marginTop="8dp"/>
<Button
android:id="@+id/loginButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login"
android:layout_marginTop="16dp"/>
</LinearLayout>
SVG Graphics
Scalable Vector Graphics
XML-based vector image format
<?xml version="1.0" encoding="UTF-8"?>
<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg">
<defs>
<linearGradient id="gradient1" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" style="stop-color:#ff0000;stop-opacity:1" />
<stop offset="100%" style="stop-color:#0000ff;stop-opacity:1" />
</linearGradient>
</defs>
<circle cx="100" cy="100" r="80" fill="url(#gradient1)" stroke="#000" stroke-width="2"/>
<text x="100" y="110" font-family="Arial" font-size="20" text-anchor="middle" fill="white">
SVG Example
</text>
<rect x="50" y="150" width="100" height="30" rx="5" ry="5"
fill="#4CAF50" stroke="#2E7D32" stroke-width="2"/>
</svg>
Benefits of XML Structures
When to Use XML vs Other Formats
XML is Best For:
- Document-oriented data with mixed content
- When schema validation is required
- Complex hierarchical structures
- When you need comments and processing instructions
- Industry standards (SOAP, RSS, XHTML)
Consider Alternatives When:
- Simple data exchange (use JSON)
- Tabular data (use CSV)
- Configuration files (consider YAML/TOML)
- Performance is critical (use Protocol Buffers)
- File size matters (XML is verbose)
XPath Query Examples
Common XPath Queries
Use these in the XPath Query tab above
// Select all product elements
//product
// Select products with price less than 100
//product[price < 100]
// Select the name of the first product
//product[1]/name
// Select all elements with an 'id' attribute
//*[@id]
// Select products in 'electronics' category
//product[@category='electronics']
// Select all price elements regardless of depth
//price
// Select the last product in the catalog
//product[last()]
// Select products with specific child elements
//product[specs/ram[@unit='GB']]