import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.StringReader;

public class TestSVGDom {
    public static void main(String[] args) {
        String svgContent = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>\n" +
                "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n" +
                "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" version=\"1.1\" width=\"7559.055118110236\" height=\"1511.8110236220473\" viewBox=\"0 0 7559.055118110236 1511.8110236220473\" xml:space=\"preserve\">\n" +
                "<desc>Created with Fabric.js 6.4.3</desc>\n" +
                "<defs>\n" +
                "</defs>\n" +
                "<rect x=\"0\" y=\"0\" width=\"100%\" height=\"100%\" fill=\"rgba(255,255,255,0)\"></rect>\n" +
                "<g transform=\"matrix(1 0 0 1 3779.5276 755.9055)\" id=\"WorkSpaceDrawType\"  >\n" +
                "<rect style=\"stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(255,0,0); fill-rule: nonzero; opacity: 1;\"  x=\"-3779.527559055118\" y=\"-755.9055118110236\" rx=\"0\" ry=\"0\" width=\"7559.055118110236\" height=\"1511.8110236220473\" />\n" +
                "</g>\n" +
                "<g transform=\"matrix(0.566 0 0 0.566 188.1766 25.8662)\" style=\"\" id=\"5p3ngaG9MM\"  >\n" +
                "\t\t<text xml:space=\"preserve\" font-family=\"Hanzi-Pinyin-Font\" font-size=\"80\" font-style=\"normal\" font-weight=\"normal\" style=\"stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(255,255,0); fill-rule: nonzero; opacity: 1; white-space: pre;\" ><tspan x=\"-331.9675\" y=\"25.1312\" >啊</tspan><tspan x=\"-251.7275\" y=\"25.1312\" >啊</tspan><tspan x=\"-171.4875\" y=\"25.1312\" >啊</tspan><tspan x=\"-91.2475\" y=\"25.1312\" >啊</tspan><tspan x=\"-11.0075\" y=\"25.1312\" >啊</tspan><tspan x=\"69.2325\" y=\"25.1312\" >啊</tspan></text>\n" +
                "</g>\n" +
                "</svg>\n";

        SAXReader reader = new SAXReader();
        Document document = null;
        try {
            document = reader.read(new StringReader(svgContent));
        } catch (DocumentException e) {
            throw new RuntimeException(e);
        }

        // 获取 SVG 根元素
        Element rootElement = document.getRootElement();
        System.out.println(rootElement.attributeValue("width"));
    }
}
