XML फॉर्मेटर
XML को तुरंत फ़ॉर्मेट, सुंदर या मिनीफ़ाई करने के लिए पेस्ट करें।
कैसे उपयोग करें
- अपना XML इनपुट क्षेत्र में पेस्ट करें।
- सुंदर करने के लिए फ़ॉर्मेट पर या कंप्रेस करने के लिए मिनिफ़ाई पर क्लिक करें।
- परिणाम कॉपी या डाउनलोड करें।
अक्सर पूछे जाने वाले प्रश्न
यदि मेरे XML में त्रुटियाँ हैं तो क्या होगा?
टूल आपके XML को ब्राउज़र के अंतर्निहित DOMParser के साथ सत्यापित करता है। सिंटैक्स त्रुटियाँ आउटपुट के ऊपर एक लाल बॉक्स में प्रदर्शित होती हैं।
क्या यह CDATA अनुभाग, टिप्पणियाँ और प्रोसेसिंग निर्देश समर्थित करता है?
हाँ। फ़ॉर्मेटर सभी XML नोड प्रकारों को संरक्षित करता है, जिनमें CDATA अनुभाग, टिप्पणियाँ और प्रोसेसिंग निर्देश शामिल हैं।
क्या कोई आकार सीमा है?
कोई कठोर सीमा नहीं है · यह आपके ब्राउज़र की मेमोरी पर निर्भर करता है। कई MB की XML फ़ाइलें आमतौर पर तुरंत फ़ॉर्मेट होती हैं।
XML का Practical Tour
XML 1.0 10 February 1998 को W3C Recommendation बना, Tim Bray, Jean Paoli, और C. M. Sperberg-McQueen द्वारा edited, Sun के Jon Bosak की chair वाले working group के साथ। Tim Bray का launch quote design intent capture करता है: «XML is extensible, internationalized, robust, simple, and built for the Web.» Current canonical version Fifth Edition है, 26 November 2008 को published, Bray, Paoli, Sperberg-McQueen, Eve Maler और François Yergeau द्वारा edited। XML directly SGML (ISO 8879:1986) से descend करता है, एक much larger, much harder-to-implement document format जिससे XML ने seldom-used parts strip करते हुए document model intact रखा।
2026 में XML अभी भी कहां है
JSON ने एक decade से REST API payloads dominate किए हैं, लेकिन XML हर जगह entrenched रहता है जहां schema rigour, document semantics, या established standards इसे lock करते हैं। यह जानना कि किसी दिन आप इसे कहां मिलेंगे, एक good formatter का आधा value है:
- Office document formats: Microsoft के
.docx/.xlsx/.pptxXML parts से भरे zip archives हैं, ECMA-376 और ISO/IEC 29500 के रूप में standardised। OpenDocument के.odt/.ods/.odp(ISO/IEC 26300) same pattern follow करते हैं। EPUB ebooks भी XML-packaged हैं। - Web vocabularies: SVG (vector graphics), MathML (mathematical notation), Atom feeds, RSS 2.0, और crawl scheduling के लिए Google और Bing द्वारा parse किया जाने वाला
sitemap.xmlprotocol। - SOAP और enterprise messaging: banking, telecom, insurance, और government back-ends अभी भी SOAP endpoints expose करते हैं, often REST facade के पीछे। XML के ऊपर industry standards में FpML for derivatives, XBRL for SEC filings, ACORD for insurance, और payment messaging के लिए ISO 20022 शामिल हैं।
- Build और config files: Maven का
pom.xml, legacy Spring beans, हर Android resource (AndroidManifest.xml,res/values/strings.xml,res/layout/*.xml), और Apple काInfo.plistअपने XML variant में। - Vertical-domain interchange: Google Earth के लिए KML, GPS traces के लिए GPX, sheet music के लिए MusicXML (4.0 published 2021), localisation के लिए XLIFF (2.1 standardised as ISO 21720 in July 2024), clinical documents के लिए HL7 v3 / CDA।
Well-Formed vs Valid: ये Same Thing नहीं हैं
XML दो different conformance levels use करता है और ये confuse करने में आसान हैं:
- Well-formed का मतलब है document XML के grammar का पालन करता है, exactly एक root element, सभी tags balanced और properly nested, attribute values quoted, entity references semicolon के साथ closed, text content में कोई unescaped
<या&नहीं। - Valid का मतलब है well-formed document additionally declared DTD, XSD (XML Schema 1.1), RELAX NG, या Schematron schema के conformant है, right places में right elements, right types के attribute values, right cardinalities में।
यह formatter केवल well-formedness check करता है। Browser का built-in DOMParser red error box में surface करने वाले parsererror element के माध्यम से पहली parse error report करता है। Schema के विरुद्ध validation के लिए different tool चाहिए (XSD के लिए Saxon, xmllint --schema के साथ libxml2, W3C validator service, etc.)।
पांच Predefined Entity References
W3C XML 1.0 §4.6 के per, «well-formed documents need not declare any of the following entities»: amp, lt, gt, apos, quot। Trailing semicolon mandatory है, XML, कुछ HTML usage के unlike, & को closing ; के बिना कभी accept नहीं करेगा।
| Entity | Character | कहां Required है |
|---|---|---|
< | < | हमेशा element content में (अन्यथा यह एक tag शुरू कर देगा) |
& | & | हमेशा (अन्यथा यह entity reference शुरू कर देगा) |
> | > | Content में ]]> sequence के अंदर required; symmetry के लिए अन्यत्र recommended |
' | ' | Single quotes से delimited attribute values के अंदर |
" | " | Double quotes से delimited attribute values के अंदर |
CDATA Sections, Comments, और Processing Instructions
तीन special syntactic features जिनका सामना XML format करने वाला कोई भी eventually करता है:
- CDATA sections:
<![CDATA[ … ]]>blocks आपको arbitrary text embed करने देते हैं<और&escape किए बिना। CDATA के अंदर एकमात्र sequence जो नहीं डाल सकते वह literal closing delimiter]]>है। XML documentation के अंदर code samples, regex patterns, या HTML fragments embed करने के लिए useful। - Comments:
<!-- … -->।--string किसी comment के अंदर illegal है। - Processing instructions:
<?target …?>। XML declaration technically PI नहीं है, लेकिन अधिकांश tooling इसे same तरह treat करती है:<?xml version="1.0" encoding="UTF-8"?>recommended first line है।
Namespaces
XML का namespace mechanism वह है जो multiple vocabularies को single document में coexist करने देता है, Atom plus custom extension, SOAP plus WS-Security headers, OOXML का main document part sister namespaces से relationships, drawings, और pictures reference करते हुए। Syntax है default namespace के लिए xmlns="…" और prefixed के लिए xmlns:prefix="…", और formatter दोनों को unchanged preserve करता है। Namespace URIs identifiers हैं, URLs नहीं, उन्हें किसी चीज़ resolve करने की ज़रूरत नहीं।
दो प्रसिद्ध XML सुरक्षा खतरे
The Billion Laughs attack। Recursively expanding entities वाली small XML file parser की memory में billions of characters तक balloon हो सकती है:
<!ENTITY lol "lol">
<!ENTITY lol2 "&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;">
<!ENTITY lol3 "&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;">
<!-- … nine more layers later, the document expands to 10^9 lols -->
Modern parsers इसे defeat करने के लिए entity expansion cap करते हैं। XXE (XML External Entity) attacks ऐसे parser को exploit करते हैं जो external entities resolve करके local files पढ़ता है (<!ENTITY xxe SYSTEM "file:///etc/passwd">) या server से SSRF requests trigger करता है। OWASP का XXE prevention cheat sheet unambiguous है: «the safest way to prevent XXE is always to disable DTDs (External Entities) completely.» Exactly यही browser का DOMParser करता है, यह DOCTYPE entity declarations entirely ignore करता है, यही कारण है कि यह client-side formatter untrusted XML feed करने के लिए भी safe है।
Pretty-Printing बनाम Minifying
- Format / Beautify nested elements indent करता है, open और close tags को अपनी own lines पर रखता है, और ऐसा output produce करता है जो read करना बहुत easier है लेकिन typically minified equivalent से 30-50% larger है। Debugging, reviewing diffs, या unfamiliar schema सीखते समय use करें।
- Minify elements के बीच सभी whitespace remove करता है जबकि text content के अंदर whitespace preserve करता है (XML whitespace को element content के अंदर default रूप से significant define करता है जब तक
xml:space="default"द्वारा override नहीं किया जाए)। Production payloads और किसी भी case के लिए use करें जहां bytes-on-the-wire matter करते हैं।
xml:space attribute आपका escape hatch है जब whitespace genuinely matter करता है, जैसे documentation में verbatim source code embed करना। Ancestor element पर xml:space="preserve" set करें और conformant processor descendants में हर space और newline byte-for-byte keep करेगा।
Common XML Errors जो Formatter Catch करता है
- Text content में Unescaped
&। Naked ampersand हमेशा invalid है;&use करें। - Mismatched या unclosed tags। सबसे common parse error। हर
<tag>को matching</tag>चाहिए (या self-closing form<tag/>use करें)। - Multiple root elements। XML document में exactly एक outermost element होना चाहिए। यदि top level पर दो siblings हैं, तो उन्हें parent में wrap करें।
- Encoding mismatch।
<?xml version="1.0" encoding="UTF-8"?>declaration file के actual byte encoding से match करना चाहिए। UTF-8 declaration के साथ UTF-16 BOM इस bug का classic version है। - Attribute values में reserved characters।
<tag attr="a<b">invalid है भले ही<quotes के अंदर harmless लगता है। - XML declaration के सामने Stray BOM। कुछ text editors silently UTF-8 BOM insert करते हैं जो strict parsers को confuse करता है।
xml:space="preserve"regions के अंदर Mixed line endings। Inconsistent CR / LF / CRLF different platforms पर round-tripping करते समय visible whitespace artefacts produce कर सकते हैं।
अधिक अक्सर पूछे जाने वाले प्रश्न
मेरा XML Format No Output क्यों Produce करता है?
Most often इसलिए कि input well-formed नहीं है। Output के ऊपर error box browser के DOMParser की पहली parse error show करता है, usually missing या mismatched tag, unescaped &, या missing root element। Error fix करें और re-run करें।
क्या मेरा XML Server पर Upload होता है?
नहीं। Formatting और minification दोनों browser के built-in DOMParser और small JavaScript serialiser के अंदर run होते हैं। आपका XML page नहीं छोड़ता, जो SOAP payloads, configuration files, और credentials, internal URLs, या sensitive customer data contain करने वाली किसी भी चीज़ के लिए important है।
क्या Tool XSD या DTD Schema के विरुद्ध Validate कर सकता है?
नहीं। Schema validation schema file load करने और उसके references resolve करने की ज़रूरत है, जो browser के well-formedness check से different problem है। XSD validation के लिए, command line पर Saxon या xmllint --schema use करें, या W3C XML Schema validator service।
क्या XML 2026 में अभी भी Relevant है, या मुझे बस JSON Use करना चाहिए?
यह इस बात पर depend करता है कि आप क्या कर रहे हैं। New REST APIs के लिए, JSON almost always सही pick है। लेकिन XML अभी भी office documents (.docx, .xlsx), enterprise messaging (SOAP, financial standards), Android resources, EPUB, RSS / Atom, SVG, और most regulated-industry interchanges के लिए default है। XML read, format, और validate करना जानना अभी भी baseline skill है; यह बस JSON की तरह हर दिन का first tool नहीं है।
«preserve all node types» का Formatter के लिए क्या मतलब है?
CDATA sections, comments, और processing instructions सभी input में exactly जैसे appear होते हैं वैसे kept रहते हैं, formatter केवल elements के बीच whitespace change करता है। इसलिए <![CDATA[ if (a < b) { … } ]]> block byte-for-byte round-trips होता है भले ही उसकी content में < characters हों जिन्हें otherwise escape करने की ज़रूरत होती।