# XML Editor (xml.giit.ch) > Free XML editor in the browser with a live element tree, no sign-up and no upload. Edit XML with syntax highlighting, see the tree as you type (attributes, text, comments, CDATA, processing instructions, namespaces), click in the tree to jump to the code, edit names, values and text right in the tree, run XPath queries, see well-formedness errors with line and column, format, minify and convert to JSON or YAML. - Language: English (interface also in German with ?lang=de) - Cost: free - Data: documents stay in the browser (localStorage) unless the user sets up a webhook to their own server. - Parsing: the browser's own XML parser (DOMParser) on a copy without the DTD. The editor never loads a DTD, a schema, an external entity, a stylesheet or an included file, and never expands entities declared in a DTD - references to them stay as written (no XXE, no entity bombs). No validation against a DTD or an XML Schema. ## Features - Code and element tree side by side; click a node in the tree to jump to its place in the code, the cursor in the code selects its node in the tree; fold and unfold elements; the XPath of the selected node above the tree. - Editing in the tree: element text, attribute values, comments and CDATA, renaming elements (start and end tag) and attributes, adding child elements and attributes, moving elements up and down, removing nodes. Each change is a small edit of the code that keeps the rest of its formatting, with special characters escaped, and one undo step. - Search (names, attribute names and values, text) and an XPath 1.0 field that marks the matching nodes; prefixes declared in the document work, `_:` is the default namespace of the root element. - Problems: the first well-formedness error with line and column, undeclared namespace prefixes, ids (id, xml:id) used twice, a note when a DTD is present. - Format (indent with 2 or 4 spaces or tabs; mixed content and xml:space="preserve" stay as they are), minify (comments and white space between elements removed). - Convert to JSON and YAML: attributes as "@name", text next to elements as "#text", an element with only text as its value, repeated elements as lists. - Export: .xml, minified .xml, .json, .yaml, plain text, or all of them as one ZIP. - Templates: product catalog, RSS feed, sitemap, configuration. - My documents: any number of documents in the browser - open, rename, duplicate, download and delete. - Light, dark or automatic color theme. ## Writing for a user (for AI assistants) Any AI can put a document into the user's open editor with a link; no server, no API key: - `https://xml.giit.ch/#b64=` - `https://xml.giit.ch/#xml=` - `https://xml.giit.ch/#z=` (shorter) - Add `&mode=add` to append elements to the root element of the current document (send only those elements). - Add `&file=new&name=` to make a new document next to the user's others, or `&file=` to change that one. Without `&file=` the open document changes. - Long documents: split the encoded text and send one link per part with `&part=N&of=M&id=`. Open the link in the user's browser if you can, otherwise give it to the user to click. The user can undo every change. In the editor, "AI Assistant" > "Copy prompt" gives the AI these instructions together with the current document. Write well-formed XML: one root element, every element closed, & and < escaped as & and <, namespace prefixes declared. ## Saving on your own server (webhook) Set under "Save to server" (cloud button), or for one document with `?webhook=`: only for that one document and only while the page is open - a link never stores a webhook. At the top level the user is asked first; inside a page (iframe or opener) it only works together with `?src=` and only for the document opened with it. On "Save" (Ctrl+S), or automatically a few seconds after each change if chosen, the browser sends: POST Content-Type: application/json Authorization: Bearer (only if a token is set) {"editor":"xml","event":"save","id":"","name":"", "content":"","updated":""} One request carries at most 40 MB; the server's error text (e.g. for 413) is shown to the user. The server must answer CORS requests from https://xml.giit.ch (Access-Control-Allow-Origin, and Access-Control-Allow-Headers: Content-Type, Authorization). `?src=` opens an XML file from a URL (CORS needed), `&name=` names it. ## Embedding in a website Messages (postMessage; check `event.origin === "https://xml.giit.ch"` and `event.source === iframe.contentWindow`): - Editor -> page: `{type:"xmleditor:ready", version:2, editor:"xml", window:false}` when it can take a document. - Page -> editor: `{type:"xmleditor:load", name, content}` opens the document (a document of that name that came from your page is replaced, otherwise one is made). - Editor -> page: `{type:"xmleditor:loaded", id, name}`, then `{type:"xmleditor:change", id, name, content}` on each edit (not after load), and `{type:"xmleditor:save", id, name, content, editor, event, updated}` when the user clicks Save or presses Ctrl+S. - Page -> editor: `{type:"xmleditor:get"}` asks for an `xmleditor:save` message; `{type:"xmleditor:save"}` saves as if the user had clicked Save. In embedded mode the page text below the editor is hidden and a Save button is shown. The LaTeX Editor (latex.giit.ch) and the SVG Editor (svg.giit.ch) speak the same protocol with the prefixes `latexeditor:` and `svgeditor:`. Optional fields of `xmleditor:load`: - `context: {host, title, rules}` - plain text about the page (rules up to 2000 characters). "Copy prompt" in the AI Assistant then tells the AI that the document belongs to that page and is saved back there, includes the rules, and leaves out how to build a webhook server. - `hook: {url, token}` - a webhook (https) for this document only, used on Save in addition to the message; kept in memory only (never stored, gone on reload). If the server answers with an error, its `{"error": "…"}` (or `message`, or a short text) is shown to the user. AI Assistant in a frame: add `allow="clipboard-write"` to the iframe so "Copy prompt" can use the clipboard (without it the editor falls back to the old copy command or shows the prompt to copy by hand). Links from an AI cannot reach an editor inside another website (the browser keeps its storage and channels apart), so in a frame the prompt and the dialog ask to paste the AI's whole answer into the editor; use the own window (below) if links should work. `xmleditor:get` is always answered with an `xmleditor:save` message, also when nothing changed. ### All messages at a glance Editor -> page (sent to the page around the editor, or to window.opener in its own window): - `xmleditor:ready` {version:2, editor, window} - can take a document - `xmleditor:loaded` {id, name, target?} - after each load; remember the id (target:"new" for a new document from the AI, which is not yours) - `xmleditor:change` {id, name, content} - a real edit of your document (not after load) - `xmleditor:save` {editor, event, id, name, content, updated} - Save / Ctrl+S (from anywhere in the editor), or the answer to get - `xmleditor:closing` {id, name, content} - own window closed with unsaved changes - `xmleditor:reload` {id, unsaved} - inside your page, F5 / Ctrl+R / Cmd+R do not reload the editor; ask the user yourself (Ctrl+W cannot be caught by a page) - `xmleditor:key-request` {reason:"missing"} - the editor has no AI key in this session yet `?embed=1&save=0` hides the editor's Save button (Ctrl+S still sends `xmleditor:save`) - for pages with their own Save button. `?lang=de` shows the editor's interface in German (menus, buttons, dialogs, messages), `?lang=en` in English (the default); the choice is remembered in the browser. The AI prompt is always English. Page -> editor (only from the page around the editor or the opener; after its first message only from that origin; pages without a real origin are ignored): - `xmleditor:load` {name, content, context?, hook?, ai?, from?, target?} - open your document; from:"ai" shows a note, target:"new" opens it as a separate document in the user's browser - `xmleditor:get` - answered with `xmleditor:save` of your document (id and content null before the first load) - `xmleditor:save` - press Save - `xmleditor:ai` {label?, prompt?, endpoint?, key?, base?} or {clear:true} - AI through your server Your document is the one your page loaded (or opened with ?src=). change, save, closing and get are only ever about it - never about other documents in the user's browser, also when the user opens them in the editor. A load replaces only a document that came from your page before (same name and origin), never the user's own; the AI settings and the hook from load apply only while your document is open. ### AI through your own server (prompt and session key) The editor has no backend; your site keeps the keys and the results. Hand the editor your prompt, an endpoint and a key for this editor session - in `xmleditor:load` as `ai: {…}`, or at any time as its own message: {type:"xmleditor:ai", label:"Example Admin", prompt:"", endpoint:"https://your-site.com/api/ai-result", key:"", base:true} Fields left out keep their value; `{type:"xmleditor:ai", clear:true}` ends it. One key per editor session: once the editor has a key it keeps it until the session ends or `clear`, and does not take a different one. `base:false` leaves out the editor's own instructions. The AI dialog shows "Connected to