【问题标题】:batik - id-attribute occurs twice in saved document蜡染 - id-attribute 在保存的文档中出现两次
【发布时间】:2011-06-04 13:27:23
【问题描述】:

我使用 Batik 两个加载一个 svg 文档并从另一个添加一个元素 文档到它,但id-attribute现在出现在保存的文档中的某些属性中 两次。所以当我试图用 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" />

【问题讨论】:

    标签: java svg batik


    【解决方案1】:

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

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

    这可能是提交bug against Batik 的工作。它真的不应该让你生成非法的xml。

    【讨论】:

      猜你喜欢
      • 2011-09-26
      • 2021-05-24
      • 1970-01-01
      • 2016-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-25
      相关资源
      最近更新 更多