蜡染 - id 属性在保存的文档中出现两次

发布于 2024-10-10 14:24:05 字数 2070 浏览 13 评论 0原文

我使用 Batik 两次加载一个 svg 文档并从另一个文档中添加一个元素 document 到它,但 id 属性现在出现在保存的文档中的某些属性中 两次。因此,当我尝试使用 Inkscape 打开保存的文档时,它只是显示错误, 它无法打开该文件。通过手动删除一些 id,现在可以使用 Inkscape 打开该文件。

非常感谢您的帮助。

……

try {
 // Load the basic symbol
 String parser = XMLResourceDescriptor.getXMLParserClassName();
 SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
 Document documentBasicSymbol = f.createSVGDocument(imgFileBasicSymbol.toURI().toString());


 // Set the fill color of the basic symbol to symbolColor
 Element element = documentBasicSymbol.getElementById("basic_symbol");
 setSymbolFillColor(element, symbolColor);


 // Load the supplementary symbol
 Document documentSupplemtarySymbol =    
f.createDocument(imgFileSupplementarySymbol.toURI().toString());

// Add it to the basic symbol:
Node nodeSupplementarySymbol = documentBasicSymbol.importNode(documentSupplemtarySymbol.getElementById("supplementary_symbol"), true);
       documentBasicSymbol.getDocumentElement().appendChild(nodeSupplementarySymbol);

storeDocument(documentBasicSymbol, "SuppElementZuBasic.svg");

部分

文档:

xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:svg="http://www.w3.org/2000/svg" zoomAndPan="magnify"
contentStyleType="text/css" id="svg2" height="100"
preserveAspectRatio="xMidYMid meet"
xmlns="http://www.w3.org/2000/svg" id="svg2" version="1.2">
  <g id="layer1" id="layer1"
  transform="translate(1.4982643,1.4982643)">
    <rect x="64.599998" y="29.674999" width="67.803474"
    style="fill:blue;stroke:#000000;stroke-width:2.0965271;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
    height="37.653473" id="basic_symbol" id="basic_symbol" />
  </g>
  <path d="m 116.10938,37.703125 0,10.8125 -47.531255,0 0,2.40625 47.531255,0 0,4.5 0,0.59375 0.90625,0.28125 13.49999,6 0.3125,-0.875 0.59375,-0.90625 -13.21874,-5.75 0,-17.0625 -2.09375,0 z"
  id="supplementary_symbol"
  style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
  id="supplementary_symbol" />

I use Batik two load one svg-document and add an element form another
document to it, but the id-attribute occurs in the saved document in some attributes now
twice. So when I'am trying to open the saved document with Inkscape, it just shows an error,
that it couldn't open the file. By deleting some of the ids manually, the file now can be open with Inkscape.

Thank you very much for your help.

...

try {
 // Load the basic symbol
 String parser = XMLResourceDescriptor.getXMLParserClassName();
 SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
 Document documentBasicSymbol = f.createSVGDocument(imgFileBasicSymbol.toURI().toString());


 // Set the fill color of the basic symbol to symbolColor
 Element element = documentBasicSymbol.getElementById("basic_symbol");
 setSymbolFillColor(element, symbolColor);


 // Load the supplementary symbol
 Document documentSupplemtarySymbol =    
f.createDocument(imgFileSupplementarySymbol.toURI().toString());

// Add it to the basic symbol:
Node nodeSupplementarySymbol = documentBasicSymbol.importNode(documentSupplemtarySymbol.getElementById("supplementary_symbol"), true);
       documentBasicSymbol.getDocumentElement().appendChild(nodeSupplementarySymbol);

storeDocument(documentBasicSymbol, "SuppElementZuBasic.svg");

...

part of the document:

xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:svg="http://www.w3.org/2000/svg" zoomAndPan="magnify"
contentStyleType="text/css" id="svg2" height="100"
preserveAspectRatio="xMidYMid meet"
xmlns="http://www.w3.org/2000/svg" id="svg2" version="1.2">
  <g id="layer1" id="layer1"
  transform="translate(1.4982643,1.4982643)">
    <rect x="64.599998" y="29.674999" width="67.803474"
    style="fill:blue;stroke:#000000;stroke-width:2.0965271;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
    height="37.653473" id="basic_symbol" id="basic_symbol" />
  </g>
  <path d="m 116.10938,37.703125 0,10.8125 -47.531255,0 0,2.40625 47.531255,0 0,4.5 0,0.59375 0.90625,0.28125 13.49999,6 0.3125,-0.875 0.59375,-0.90625 -13.21874,-5.75 0,-17.0625 -2.09375,0 z"
  id="supplementary_symbol"
  style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
  id="supplementary_symbol" />

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

踏雪无痕 2024-10-17 14:24:07

如果您不需要使用id,您可以尝试3 个参数 importNode,第三个值 (trimIds) 设置为

除此之外,我唯一能想到的就是遍历附加元素的 DOM 并调整/删除 id。

可能需要提交针对 Batik 的错误。它确实不应该让你生成非法的 xml。

If you don't need to use the id, you might try the 3 argument importNode with the third value (trimIds) set to true.

Other than that, the only other thing I can think of is to walk the DOM of your additional element and adjust/remove the ids.

It's probably work filing a bug against Batik. It really should not let you generate illegal xml.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文