drawio-format-adapter — independently scanned and version-tracked by SaferSkills.
SaferSkills independently audited drawio-format-adapter (Agent Skill) and scored it 100/100 (green). The audit ran 55 deterministic rules across Security, Supply Chain, Maintenance, Transparency, and Community; it found 0 high-severity and 0 lower-severity findings. The full rule-by-rule trace and per-finding evidence are below. Free, methodology-open.
Findings & checks · 0 flagged
Every scanned point with the score it earned and what moved between them.
First recorded scan — no prior version to compare against.
The primary manifest — the file an agent reads to learn what this artifact does.
This document provides detailed explanations of draw.io XML file structure, syntax rules, and usage methods, facilitating developers' understanding and use of draw.io XML format for programmatic generation and modification of graphics.
Important Note: This document focuses on XML file structure and core element attributes. First read reference/xml-reference.md. For detailed style properties, HTML tag usage, edge connections, container grouping, layer management, and other content, please refer to reference/xml-reference.md.
draw.io XML files use a hierarchical structure, forming a complete tree structure from the root element to the lowest-level graphic elements:
<?xml version="1.0" encoding="UTF-8"?>
<mxfile>
<diagram name="Page-1" id="diagram-id">
<mxGraphModel
dx="1422"
dy="762"
grid="1"
gridSize="10"
guides="1"
tooltips="1"
connect="1"
arrows="1"
fold="1"
page="1"
pageScale="1"
pageWidth="827"
pageHeight="1169"
math="0"
shadow="0"
>
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<!-- Graphic element definitions -->
</root>
</mxGraphModel>
</diagram>
</mxfile>Definition: The root element of the XML document, containing one or more diagram elements.
Attribute Description:
| Attribute Name | Data Type | Required | Description | Default Value |
|---|---|---|---|---|
| version | string | No | File format version | None |
| host | string | No | Application that created this file | None |
| modified | string | No | Last modification time (ISO 8601 format) | None |
| agent | string | No | Client information that created this file | None |
| etag | string | No | Entity tag for cache control | None |
| type | string | No | File type identifier | None |
Example:
<mxfile host="app.diagrams.net" modified="2024-01-15T08:30:00.000Z" agent="5.0" version="21.0.0" etag="abc123" type="device">Definition: Represents an independent drawing page; a mxfile can contain multiple diagram elements.
Attribute Description:
| Attribute Name | Data Type | Required | Description | Default Value |
|---|---|---|---|---|
| name | string | Yes | Page name, displayed on page tab | "Page-1" |
| id | string | Yes | Page unique identifier | Auto-generated |
Child Elements:
mxGraphModel: Contains actual graphic data (required and unique)Multi-page Example:
<mxfile>
<diagram name="Architecture Diagram" id="page1">
<mxGraphModel>...</mxGraphModel>
</diagram>
<diagram name="Flowchart" id="page2">
<mxGraphModel>...</mxGraphModel>
</diagram>
</mxfile>Definition: The core container of the graphic model, defining global canvas attributes and coordinate system.
Attribute Description:
| Attribute Name | Data Type | Range | Default Value | Description |
|---|---|---|---|---|
| dx | number | Any value | 1422 | View horizontal offset (pixels) |
| dy | number | Any value | 762 | View vertical offset (pixels) |
| grid | boolean | 0, 1 | 1 | Whether to display grid |
| gridSize | number | > 0 | 10 | Grid size (pixels) |
| guides | boolean | 0, 1 | 1 | Whether to display alignment guides |
| tooltips | boolean | 0, 1 | 1 | Whether to enable tooltips |
| connect | boolean | 0, 1 | 1 | Whether to enable connection function |
| arrows | boolean | 0, 1 | 1 | Whether to display arrows |
| fold | boolean | 0, 1 | 1 | Whether to enable fold function |
| page | boolean | 0, 1 | 1 | Whether to display page boundaries |
| pageScale | number | > 0 | 1 | Page zoom ratio |
| pageWidth | number | > 0 | 827 | Page width (pixels, A4 paper approx 827px) |
| pageHeight | number | > 0 | 1169 | Page height (pixels, A4 paper approx 1169px) |
| math | boolean | 0, 1 | 0 | Whether to enable math typesetting (LaTeX support) |
| shadow | boolean | 0, 1 | 0 | Whether to display shadow effects |
Child Elements:
root: Container containing all graphic elements (required and unique)Definition: Container for all graphic elements, using a flat storage structure.
Child Elements:
mxCell id="0" - Root node, no actual graphic meaningmxCell id="1" parent="0" - Default parent container, parent of all top-level elementsStructure Example:
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<!-- User-created graphic elements below -->
<mxCell id="2" vertex="1" parent="1">...</mxCell>
<mxCell id="3" vertex="1" parent="1">...</mxCell>
<mxCell id="4" edge="1" parent="1" source="2" target="3">...</mxCell>
</root>Definition: mxCell is the most basic graphic unit in draw.io; all visible graphics (including nodes, edges, groups) are instances of mxCell.
Attribute Description:
| Attribute Name | Data Type | Required | Range | Default Value | Description |
|---|---|---|---|---|---|
| id | string | Yes | Unique string | None | Element unique identifier, must be unique throughout the document |
| value | string | No | Any text | "" | Display text content, supports HTML entity encoding and HTML tags |
| style | string | No | Style string | "" | Style definition, multiple key-value pairs separated by semicolons |
| parent | string | Yes | Parent element ID | None | Parent element ID, determines element hierarchical relationship |
| visible | boolean | No | 0, 1 | 1 | Whether visible |
| collapsed | boolean | No | 0, 1 | 0 | Whether collapsed (for groups) |
| connectable | boolean | No | 0, 1 | 1 | Whether connectable |
| source | string | Conditionally required | Node ID | None | Edge's source node ID (only edges need this) |
| target | string | Conditionally required | Node ID | None | Edge's target node ID (only edges need this) |
| edge | boolean | Conditionally required | 0, 1 | 0 | Marked as edge (required for edges) |
| vertex | boolean | Conditionally required | 0, 1 | 0 | Marked as node (required for nodes) |
| placeholder | boolean | No | 0, 1 | 0 | Whether to use placeholder |
| Attribute Name | Data Type | Description |
|---|---|---|
| vertex | boolean | Must be set to 1, identifies this as a node |
| Attribute Name | Data Type | Required | Description |
|---|---|---|---|
| edge | boolean | Yes | Must be set to 1, identifies this as an edge |
| source | string | Yes | Source node ID |
| target | string | Yes | Target node ID |
| value | string | No | Label text on edge |
Definition: Defines geometric position and dimension information for graphic elements.
Attribute Description:
| Attribute Name | Data Type | Required | Range | Default Value | Description |
|---|---|---|---|---|---|
| x | number | No | Any value | 0 | Element top-left X coordinate (pixels) |
| y | number | No | Any value | 0 | Element top-left Y coordinate (pixels) |
| width | number | No | ≥ 0 | 0 | Element width (pixels) |
| height | number | No | ≥ 0 | 0 | Element height (pixels) |
| as | string | Yes | "geometry" | None | Fixed value, identifies this as geometric information |
| relative | boolean | No | 0, 1 | 0 | Whether to use relative coordinates |
| Attribute Name | Data Type | Required | Range | Default Value | Description |
|---|---|---|---|---|---|
| relative | boolean | Yes | 0, 1 | 1 | Edge must use relative coordinates (set to 1) |
| as | string | Yes | "geometry" | None | Fixed value |
Edge mxGeometry Child Elements:
| Child Element | Description |
|---|---|
| mxPoint (as="sourcePoint") | Source point coordinates (used when connection point is not at node center) |
| mxPoint (as="targetPoint") | Target point coordinates |
| mxPoint (as="offset") | Label offset |
| Array (as="points") | Path point array, defining polyline path |
Edge Geometry Example:
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="200" y="150"/>
<mxPoint x="300" y="150"/>
</Array>
</mxGeometry>Definition: Represents a 2D coordinate point.
Attribute Description:
| Attribute Name | Data Type | Required | Description |
|---|---|---|---|
| x | number | Yes | X coordinate |
| y | number | Yes | Y coordinate |
| as | string | Conditionally required | Purpose identifier (sourcePoint/targetPoint/offset) |
Definition: Used to store edge path point arrays.
Attribute Description:
| Attribute Name | Data Type | Required | Description |
|---|---|---|---|
| as | string | Yes | Fixed value "points" |
Child Elements:
mxPoint elements, defining various turning points of polyline pathSee also: Common styles in reference/xml-reference.md
Common basic shapes include rectangle, ellipse, circle, rhombus, cylinder, etc. Standard examples can be found in xml-reference.md.
<mxCell id="rect1" value="Rectangle" vertex="1" parent="1">
<mxGeometry x="100" y="100" width="120" height="60" as="geometry"/>
</mxCell><mxCell id="diamond1" value="Diamond" vertex="1" parent="1"
style="rhombus;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;">
<mxGeometry x="100" y="250" width="100" height="100" as="geometry"/>
</mxCell><mxCell id="cylinder1" value="Database" vertex="1" parent="1"
style="shape=cylinder3;whiteSpace=wrap;html=1;boundedLbl=1;backgroundOutline=1;size=15;fillColor=#e1d5e7;strokeColor=#9673a6;">
<mxGeometry x="300" y="250" width="100" height="80" as="geometry"/>
</mxCell><mxCell id="cloud1" value="Cloud" vertex="1" parent="1"
style="ellipse;shape=cloud;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeColor=#666666;">
<mxGeometry x="500" y="250" width="120" height="80" as="geometry"/>
</mxCell><mxCell id="doc1" value="Document" vertex="1" parent="1"
style="shape=note;whiteSpace=wrap;html=1;backgroundOutline=1;darkOpacity=0.05;fillColor=#ffff88;strokeColor=#36393d;">
<mxGeometry x="100" y="400" width="80" height="100" as="geometry"/>
</mxCell><mxCell id="storage1" value="Data Storage" vertex="1" parent="1"
style="shape=partialRectangle;whiteSpace=wrap;html=1;left=0;right=0;fillColor=none;strokeColor=#666666;">
<mxGeometry x="300" y="400" width="100" height="60" as="geometry"/>
</mxCell>See also: Edge connection description in xml-reference.md
Connector lines (edges) are used to connect various nodes. Common styles include straight lines, arrowed connections, dashed lines, polylines, etc. Detailed examples and automatic routing explanations can be found in xml-reference.md.
<mxCell id="edge1" edge="1" parent="1" source="rect1" target="ellipse1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>Note: Each edge's mxCell must contain a <mxGeometry relative="1" as="geometry" /> child element.
See also: Containers and groups in xml-reference.md
Swimlane diagrams are used for cross-functional flowcharts. Include basic swimlanes, vertical swimlanes, BPMN-style swimlanes, etc. Detailed usage can be found in xml-reference.md.
UML class diagrams, interfaces, relationships (inheritance, implementation, association, composition, etc.) can be implemented using specialized styles. Examples can be found in xml-reference.md style descriptions.
<mxCell id="class1" value="<b>ClassName</b>
- attribute: Type
+ method(): ReturnType"
vertex="1" parent="1"
style="swimlane;fontStyle=1;align=center;verticalAlign=top;childLayout=stackLayout;horizontal=1;startSize=26;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=1;marginBottom=0;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;">
<mxGeometry x="100" y="100" width="160" height="100" as="geometry"/>
</mxCell>Standard flowchart elements include: start/end (rounded rectangle), process (rectangle), decision (rhombus), input/output (parallelogram), etc. These can all be implemented through different shape styles.
<mxCell id="start1" value="Start" vertex="1" parent="1"
style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;arcSize=50;">
<mxGeometry x="100" y="100" width="80" height="40" as="geometry"/>
</mxCell><mxCell id="decision1" value="Decision?" vertex="1" parent="1"
style="rhombus;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;">
<mxGeometry x="450" y="90" width="80" height="80" as="geometry"/>
</mxCell>See also: HTML tag usage explanation in xml-reference.md
Important Note: When using HTML tags (such as <b>, <br>, <i>, <u>, etc.), you must include html=1 in the style.
The style attribute is a semicolon-separated key-value pair string:
key1=value1;key2=value2;key3=value3;Rule Description:
;=; to separate multiple style definitionsSee also: Style property description in xml-reference.md
Style properties include shape, fill, stroke, text, edge/arrow, connection points, container/grouping, image, and other types. Complete tables can be found in xml-reference.md.
Quick reference for common style key-value pairs:
shape, rounded, aspectfillColor, gradientColor, shadowstrokeColor, strokeWidth, dashedfontColor, fontSize, fontStyle, align, htmlendArrow, edgeStyle, curvedcontainer, collapsible, startSizeSee also: Containers and groups in xml-reference.md
Grouping organizes multiple elements together for unified movement, scaling, and collapsing.
<!-- Group container -->
<mxCell id="group1" value="Group Title" vertex="1" parent="1"
style="group;fillColor=none;strokeColor=default;verticalAlign=top;fontStyle=1;"
connectable="0" collapsible="1">
<mxGeometry x="100" y="100" width="300" height="200" as="geometry"/>
</mxCell>
<!-- Child elements in group, parent points to group -->
<mxCell id="child1" value="Child Element 1" vertex="1" parent="group1"
style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;">
<mxGeometry x="20" y="40" width="100" height="60" as="geometry"/>
</mxCell>Key Points:
style="group"parent attribute points to the group container's IDCollapsible containers use collapsible=1 and collapsed attributes to control fold state.
<mxCell id="foldable1" value="Collapsible Container" vertex="1" parent="1"
style="swimlane;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;startSize=30;collapsible=1;"
collapsed="0">
<mxGeometry x="100" y="100" width="200" height="150" as="geometry"/>
</mxCell>Attribute Description:
collapsible=1: Enable folding functioncollapsed="0": Initial expanded state (0=expanded, 1=collapsed)startSize: Title bar size retained after foldingSee also: Layer description in xml-reference.md
Layers control visibility and z-order. Each element belongs to a layer; element display can be controlled by switching layers.
<mxGraphModel>
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<mxCell id="2" value="Layer Name" parent="0"/>
<!-- Elements in layer 2 -->
<mxCell id="20" value="Node" style="..." vertex="1" parent="2">
<mxGeometry x="100" y="100" width="120" height="60" as="geometry"/>
</mxCell>
</root>
</mxGraphModel>Add hyperlinks to nodes via the link attribute.
<mxCell id="link1" value="Click to Visit" vertex="1" parent="1"
style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;fontColor=#0000FF;underline=1;"
link="https://www.example.com">
<mxGeometry x="100" y="100" width="120" height="40" as="geometry"/>
</mxCell>Attribute Description:
link: Target URL or internal page referencefontColor=#0000FF and underline=1: Visual cue indicating this is a linkAdd hover tooltips to nodes via the tooltip attribute.
<mxCell id="tooltip1" value="Hover to View" vertex="1" parent="1"
style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;"
tooltip="This is detailed tooltip information">
<mxGeometry x="100" y="200" width="120" height="40" as="geometry"/>
</mxCell>See also: Metadata and placeholders in xml-reference.md
Placeholders allow referencing element attribute values in text using %propertyName% syntax.
<mxCell id="placeholder1" value="Name: %name%" vertex="1" parent="1"
style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;"
placeholders="1"
name="Example Name">
<mxGeometry x="100" y="300" width="150" height="60" as="geometry"/>
</mxCell>System placeholders: %id%, %value%, %parent%, %source%, %target%, %width%, %height%, etc.
Control edge connection positions via exitX/Y and entryX/Y.
<mxCell id="edge1" edge="1" parent="1" source="node1" target="node2"
style="endArrow=classic;html=1;strokeColor=#666666;exitX=1;exitY=0.5;entryX=0;entryY=0.5;">
<mxGeometry relative="1" as="geometry"/>
</mxCell>Description:
exitX=1;exitY=0.5: Exit from the center of the right side of source nodeentryX=0;entryY=0.5: Enter at the center of the left side of target node<!-- Layer container -->
<mxCell id="layer1" value="Background Layer" vertex="1" parent="0"
style="locked=1;"
visible="1">
<mxGeometry x="0" y="0" width="0" height="0" as="geometry"/>
</mxCell>
<!-- Default layer -->
<mxCell id="1" parent="0"/>
<!-- Elements in background layer -->
<mxCell id="bg1" value="" vertex="1" parent="layer1"
style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeColor=none;">
<mxGeometry x="0" y="0" width="827" height="1169" as="geometry"/>
</mxCell>| UI Operation | XML Element | Attribute Change |
|---|---|---|
| Insert rectangle | mxCell | vertex="1", style contains shape=rectangle |
| Insert ellipse | mxCell | vertex="1", style contains ellipse |
| Draw connector | mxCell | edge="1", source/target point to node IDs |
| Add text | mxCell | value attribute stores text content |
| Move element | mxGeometry | x/y coordinate change |
| Resize | mxGeometry | width/height change |
| Set color | style | fillColor/strokeColor change |
| Group operation | parent attribute | Child element parent points to group ID |
| UI Setting | style attribute | Example Value |
|---|---|---|
| Fill color | fillColor | #dae8fc, #FF0000 |
| Stroke color | strokeColor | #6c8ebf, none |
| Stroke width | strokeWidth | 1, 2, 3 |
| Font size | fontSize | 12, 14, 16 |
| Font color | fontColor | #333333 |
| Corner radius | arcSize | 10, 20, 50 |
| Shadow effect | shadow | 0, 1 |
| UI Function | XML Implementation |
|---|---|
| Fold/Expand | collapsed attribute, collapsible=1 style |
| Hyperlink | link attribute |
| Tooltip | tooltip attribute |
| Placeholder | placeholders="1" + custom attributes |
| Layer | Different parent containers |
| Alignment guides | guides=1 (mxGraphModel attribute) |
| Grid | grid=1, gridSize=10 |
Method 1: Direct Open
.drawio or .xml fileMethod 2: Import from Text
Method 3: Drag and Drop Import Directly drag the XML file into the draw.io editor
Method 1: Save as File
.drawio fileMethod 2: Export as XML
Method 3: View Source Code
#### 1. ID Uniqueness
#### 2. Parent Relationship
#### 3. Encoding Issues

 for line breaks#### 4. Coordinate System
#### 5. Style Syntax
#### 6. Compatibility
#### 7. Compressed Format
#### Best Practices
# Pseudo-code example
def create_node(id, value, x, y, width, height, style):
return f'''<mxCell id="{id}" value="{value}" vertex="1" parent="1" style="{style}">
<mxGeometry x="{x}" y="{y}" width="{width}" height="{height}" as="geometry"/>
</mxCell>'''| Color Name | Hexadecimal | Suggested Use |
|---|---|---|
| Light Blue | #dae8fc | General nodes, services |
| Dark Blue | #6c8ebf | Borders, emphasis |
| Light Green | #d5e8d4 | Success, normal state |
| Dark Green | #82b366 | Borders, confirmation |
| Light Yellow | #fff2cc | Warning, attention |
| Dark Yellow | #d6b656 | Borders, warning |
| Light Red | #f8cecc | Error, danger |
| Dark Red | #b85450 | Borders, error |
| Light Purple | #e1d5e7 | Data, storage |
| Dark Purple | #9673a6 | Borders, data |
| Gray | #f5f5f5 | Background, grouping |
| Dark Gray | #666666 | Borders, text |
| Semantic | Fill Color | Border Color |
|---|---|---|
| Input/Source | #dae8fc | #6c8ebf |
| Processing/Transform | #d5e8d4 | #82b366 |
| Output/Target | #e1d5e7 | #9673a6 |
| Decision | #fff2cc | #d6b656 |
| Exception/Error | #f8cecc | #b85450 |
| External System | #f5f5f5 | #666666 |
<!-- -->), otherwise the file will not display properly.Use the following command to check if xmllint is installed:
chmod +x scripts/check_xmllint_install.sh
bash scripts/check_xmllint_install.shUse the following command to validate the XML file:
# check the xml file
xmllint --noout file_name.drawio
# check the xml string
echo '<root><node attr="val">Context</node></root>' | xmllint --noout -If the XML format is correct, there will be no output. If there are format errors, xmllint will report the specific error and line number.Then you can fix the XML format according to the error message.
After the XML format is fixed, you must use the xmllint tool to check the format again until there are no errors . Only XML files that pass xmllint validation can be successfully imported into draw.io.
This document provides detailed explanations of draw.io XML format specifications, including:
After mastering this knowledge, developers can:
~30 seconds. Free. No account. Every finding cites a rule and a line of evidence.