먼저 inkscape:
은 네임 스페이스가 아니므로 XML 루트 요소에 정의 된 네임 스페이스를 참조하기에 편리합니다. 네임 스페이스는 http://www.inkscape.org/namespaces/inkscape
이고 XML에 따라 inkscape:groupmode
은 foo:groupmode
과 동일 할 수 있습니다. 물론 <g>
요소는 SVG 네임 스페이스의 일부인 http://www.w3.org/2000/svg
입니다.
이
from lxml import etree
root = etree.Element('{http://www.w3.org/2000/svg}svg')
g = etree.SubElement(root, '{http://www.w3.org/2000/svg}g', id='layer-id')
당신을 얻을 것이다 :
<ns0:svg xmlns:ns0="http://www.w3.org/2000/svg">
<ns0:g id="layer-id"/>
</ns0:svg>
은 잉크 스케이프 - 특정 속성에 추가하려면, 당신은이 작업을 수행 할 것입니다 : LXML와 적절한 출력을 생성하려면, 다음과 같이 시작하는 것입니다
g.set('{http://www.inkscape.org/namespaces/inkscape}groupmode', 'layer')
g.set('{http://www.inkscape.org/namespaces/inkscape}label', 'layer-label')
당신을 얻을 것이다 :
<ns0:svg xmlns:ns0="http://www.w3.org/2000/svg">
<ns0:g xmlns:ns1="http://www.inkscape.org/namespaces/inkscape" id="layer-id" ns1:groupmode="layer" ns1:label="layer-label"/>
</ns0:svg>
믿거 나 말거나 당신이 원하는 것입니다. 루트 요소를 만들 때 nsmap=
매개 변수를 전달하여 조금 더 네임 스페이스 레이블을 정리할 수 있습니다. 이 같은 장소에두고
NSMAP = {
None: 'http://www.w3.org/2000/svg',
'inkscape': 'http://www.inkscape.org/namespaces/inkscape',
}
root = etree.Element('{http://www.w3.org/2000/svg}svg', nsmap=NSMAP)
, 최종 결과는 다음과 같을 것이다 다음 LXML documentation에
<svg xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns="http://www.w3.org/2000/svg">
<g id="layer-id" inkscape:label="layer-label" inkscape:groupmode="layer"/>
</svg>
더 많은 정보를.
Works! 자세한 답변을 주셔서 감사합니다. –