Embed the XML Editor in your website
For developers: how to put the XML Editor into your own page - in an iframe, in a window of its own or as a read-only viewer - and how documents, saves and AI results travel between the editor and your server. You need no sign-up and no key from us.
Any https page (and localhost) can embed the editor with an <iframe> and ?embed=1 - no sign-up, no key. Embedded, the editor hides the page text and shows a Save button. There are four ways to get the document in and out.
1. Open a file from a link, save to your server
src= opens a file (your server must allow CORS), webhook= makes "Save" (Ctrl+S) send the document to that address. Add &auto to save after every change.
<iframe src="https://xml.giit.ch/?embed=1&src=https://your-site.com/data/catalog.xml&webhook=https://your-site.com/save.php"
allow="clipboard-write" style="width:100%;height:800px;border:0"></iframe>
The webhook gets a POST with JSON { editor: "xml", event: "save", id, name, content, updated }. A link carries no token (it would end up in server logs and the browser history), so a webhook in the address suits a save address that needs none, for example on localhost or in your intranet. For a public server, hand the webhook over with a token in xmleditor:load (hook: { url, token }) and check it, as this small PHP script does:
<?php
header('Access-Control-Allow-Origin: https://xml.giit.ch');
header('Access-Control-Allow-Headers: Content-Type, Authorization');
header('Access-Control-Allow-Methods: POST, OPTIONS');
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') exit;
if (($_SERVER['HTTP_AUTHORIZATION'] ?? '') !== 'Bearer SECRET') { http_response_code(403); exit; }
$d = json_decode(file_get_contents('php://input'), true);
$name = preg_replace('/[^\w\- ]/u', '_', $d['name']);
file_put_contents(__DIR__ . "/data/$name.xml", $d['content']);
echo '{"ok":true}';
2. Your page holds the document (postMessage)
The editor says xmleditor:ready, your page answers with xmleditor:load, the editor reports xmleditor:loaded, xmleditor:change on real edits and xmleditor:save when the user saves. Your page may send xmleditor:get (the current state) or xmleditor:save (press Save). Saving then goes through your own login and session.
<iframe id="ed" src="https://xml.giit.ch/?embed=1" allow="clipboard-write" style="width:100%;height:800px;border:0"></iframe>
<script>
const ed = document.getElementById('ed');
const ORIGIN = 'https://xml.giit.ch';
addEventListener('message', async e => {
if (e.source !== ed.contentWindow || e.origin !== ORIGIN) return;
const m = e.data;
if (m.type === 'xmleditor:ready') { // the editor is ready: hand it the document
ed.contentWindow.postMessage({
type: 'xmleditor:load',
name: 'Catalog',
content: await (await fetch('/data/catalog.xml')).text()
}, ORIGIN);
}
if (m.type === 'xmleditor:change') document.title = '● not saved'; // a real edit
if (m.type === 'xmleditor:save') { // the user clicked "Save"
await fetch('/api/save', { method: 'POST', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name: m.name, content: m.content }) });
document.title = 'Saved';
}
});
// A save button on your own page: the answer comes as xmleditor:save
function saveNow() { ed.contentWindow.postMessage({ type: 'xmleditor:get' }, ORIGIN); }
</script>
AI Assistant inside your page: it works in the frame too. With allow="clipboard-write" on the iframe, "Copy prompt" uses the clipboard directly (otherwise the editor falls back to the old copy command, or shows the prompt to copy by hand). A link the AI sends cannot reach an editor inside another website, so the editor tells the AI and the user to paste the AI's whole answer into the editor instead - or open the editor in a window of its own.
3. In a window of its own
window.open("https://xml.giit.ch/?embed=window", "xmleditor-17") opens the full editor in its own window and speaks the same messages with window.opener. Links from an AI reach it there. xmleditor:load may also carry context: { host, title, rules } - the AI prompt then says where the document belongs and follows your rules - and hook: { url, token }, a webhook for this document only that is never stored. Closing the window with unsaved changes sends xmleditor:closing.
4. AI through your own server
Hand the editor your own prompt, an address on your site and a key for this editor session. The AI dialog then shows "Connected to" your site, what you tell the AI, and the choice change the current document or make a new one; Copy prompt puts it all together. The AI posts its result with the key to your server, and your page opens it in the editor - a new document opens separately and stays in the user's browser. One key per editor session: it stays valid while the editor is open, and only while it has none the editor asks for it with xmleditor:key-request. The editor never sends the key itself and never stores it; the address must be https on your own host or a subdomain of it.
Illustrative pseudocode. Implement session lookup, heartbeat, revocation, authorization and draft storage before use. The key-request handler belongs inside the message listener after the source and origin checks.
const key = async () => (await fetch('/api/ai-key.php?doc=17')).json(); // one key per editor session
const k = await key();
ed.contentWindow.postMessage({ type: 'xmleditor:load', name: 'Catalog', content, ai: {
label: 'My Site', prompt: 'Keep the sku attributes. Prices in CHF.',
endpoint: 'https://your-site.com/api/ai-result.php', key: k.key } }, ORIGIN);
// remember the id from xmleditor:loaded and ignore change/save/closing with another id
// only while the editor has no key:
if (m.type === 'xmleditor:key-request') { const k = await key(); ed.contentWindow.postMessage({ type: 'xmleditor:ai', key: k.key }, ORIGIN); }
// while the editor is open, tell your server every minute; closing the editor or the page voids the key
setInterval(() => fetch('/api/ai-key.php?alive=' + k.key.slice(0, 8)), 60000);
// your server has a result (polling, SSE …): target is "current" or "new"
ed.contentWindow.postMessage({ type: 'xmleditor:load', name: 'Catalog', content: draft, from: 'ai', target }, ORIGIN);
<?php // api/ai-key.php - the key of this editor session of the logged-in user (your page calls it)
session_start(); // check that the user may edit this document
$key = bin2hex(random_bytes(24));
$_SESSION['ai'][hash('sha256', $key)] = ['doc' => (int)$_GET['doc'], 'seen' => time()]; // or in your database; ?alive= sets seen again
echo json_encode(['key' => $key]);
<?php // api/ai-result.php - the AI posts here (no CORS headers: AIs call it from a server)
$key = preg_replace('/^Bearer\s+/', '', $_SERVER['HTTP_AUTHORIZATION'] ?? '');
$row = find_key(hash('sha256', $key)); // your database: not voided, seen in the last 3 minutes
if (!$row) { http_response_code(401); exit('{"ok":false,"error":"key not valid"}'); }
$d = json_decode(file_get_contents('php://input', false, null, 0, 2000000), true);
save_draft($row['doc'], $d['content'], $d['target'] === 'new' ? 'new' : 'current'); // your page shows it with xmleditor:load
echo '{"ok":true}';
Make keys with at least 128 random bits, store only their hash, bind each to the logged-in user, the document and this editor session, make one per session, keep it valid only while your page reports the session as open, and void it when the editor or the page closes.
Your own AI dialog and answering instructions: with dialog: "page" in ai, a click on AI Assistant sends xmleditor:ai-click with a request id; answer { type: "xmleditor:ai-click", request, handled: true } within 300 ms and show your own dialog - otherwise the editor opens its own. answer: "…" puts your text in place of the "HOW TO ANSWER" part of the copied prompt ("none" leaves the part out, "" brings the editor's part back); the prompt then carries no key. When your server gives no key, answer xmleditor:key-request with { type: "xmleditor:ai", decline: true, message: "…" }: the editor stops waiting at once and shows your message after your host - write it in your page's language. In the prompt the document always stands in a fence longer than any run of backticks in it, marked as data.
The whole protocol is in llms.txt - give it to an AI and it builds the connection for your system. The other giit editors work the same way with their own prefix - editors.giit.ch.
Show a document read-only (viewer)
?viewer=1 shows only the finished document: no code, no tools, nothing can be changed, and nothing is stored in the browser. The document comes from a link (#b64=, ?src=), from your page with xmleditor:load, or by POST as a normal form to post.php: the field content as text or b64 as base64, optionally name, at most 20 MB of text.
<form method="post" action="https://xml.giit.ch/post.php?viewer=1" target="_blank">
<input type="hidden" name="name" value="Report">
<input type="hidden" name="b64" value="…">
<button>Open</button>
</form>
Without viewer=1 the document opens in the normal editor. Either way it is kept in memory only: it is not stored on the server and does not join "My documents". Opened directly, the viewer says that the content comes from a third party.
Templates with placeholders
When your server fills placeholders into the XML before it is used, add template=mustache for {{name}}, {{#name}} … {{/name}} and {{^name}} … {{/name}}, or template=angle for <<name>> and <<?name>> … <</?name>>. The list of problems reads every tag as one placeholder and reports a section left open, a stray end tag, an end tag in the wrong order and a tag with an unknown sign; the code shows the tags as written. An id or a namespace prefix that holds a placeholder counts as filled later, and Format keeps every tag.
Send your placeholders with examples, and the tree shows the document filled with them: sections by their example state, a list once per example row. A placeholder without an example shows its label in brackets, such as [Name]. The switch Template in the tree’s bar shows the tree with the tags as text, Examples brings the examples back; the box Placeholders below the code puts a tag at the cursor. A click on a row selects its node in the code, also for each row of a list; a part that shows an example is edited in the code. Examples are shown as text, stay in memory only and never reach your page: saving, change, get, the webhook and every export carry the template as written.
frame.contentWindow.postMessage({ type: 'xmleditor:template',
placeholders: [
{ name: 'name', kind: 'value', label: 'Name', example: 'John Doe' },
{ name: 'hasNote', kind: 'section', label: 'With a note', shown: true },
{ name: 'items', kind: 'list', label: 'Items',
fields: [ { name: 'label', label: 'Item' }, { name: 'quantity', label: 'Quantity' } ],
rows: [ { label: 'Chair', quantity: '2' }, { label: 'Table', quantity: '1' } ] } ] }, ORIGIN);
// or the same object as the field template of xmleditor:load; { type: 'xmleditor:template', clear: true } ends it
<iframe src="https://xml.giit.ch/?embed=1&template=mustache" allow="clipboard-write" style="width:100%;height:800px;border:0"></iframe>