下面我有两个XML(SVG)文档。原件已在Adobe Illustrator中打开并刚刚导出。就是这样。
不同之处在于我无法使任何XPath表达式与导出的文件一起使用!
xmllint --xpath '/svg' org.svg
为我提供了<svg>
元素的全部内容,包括子节点,而xmllint --xpath '/svg' ill.svg
只输出XPath set is empty
。
除了DOCTYPE
之外,我在两个文件之间找不到任何有意义的区别,但手动添加它没有任何区别。
org.svg
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg viewBox = "0 0 800 600" version = "1.1">
<!-- Oslo -->
<path
id = "Oslo_0"
fill = "green"
stroke = "white" stroke-width = "1"
d = "M294.816,483.766l0.71,1.432l3.134,4.696c0.528,0.793,0.701,1.776,0.47,2.701l-0.193,0.793 c0.659,0.131,1.29,0.391,1.77,0.874l0.435,0.417l1.049,0.502l3.259,1.569c1.294,0.518,1.551,1.756,1.551,3.146v1.786l1.96,3.442 c0.299,0.741,0.522,1.541,0.268,2.297l-0.269,1.359l0.485,0.119l0.408,0.702L311.49,511h0.6h2.598h0.947l-1.272-6.497 c-0.105-0.525-0.179-1.427-0.03-1.943l1.435-5.858l-0.806-0.671L314,495.032v-0.824c0-0.892,1.77-1.751,2.4-2.383l1.436-0.351 l-0.061-1.118l-0.781-0.433l-0.322-0.211l-4.858-3.25c-0.575-0.384-1.002-0.918-1.256-1.563l-2.469-4.064 c-0.158-0.396-1.089-0.826-1.089-1.252v-2.102l0.287-2.98l-1.477-2.634c-0.224-0.301-0.133-0.605-0.25-0.963l-1.164-2.435 c-0.118-0.357-0.396-0.695-0.396-1.073v-0.346l-2.684-1.15c-0.335-0.168-0.577,0.64-0.844,0.376L300.125,467h-3.611l0.986,2.668 c0.297,1.207-0.083,2.15-1,2.989l-6.98,6.237l4.508,3.928C294.35,483.103,294.624,483.383,294.816,483.766z"
/>
</svg>
ill.svg
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 18.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="612px" height="792px" viewBox="0 0 612 792" enable-background="new 0 0 612 792" xml:space="preserve">
<path id="Oslo_0" fill="#008000" stroke="#FFFFFF" d="M225.5,536.6l0.5,1.1l2.4,3.6c0.4,0.6,0.5,1.4,0.4,2.1l-0.1,0.6
c0.5,0.1,1,0.3,1.4,0.7l0.3,0.3l0.8,0.4l2.5,1.2c1,0.4,1.2,1.3,1.2,2.4v1.4l1.5,2.6c0.2,0.6,0.4,1.2,0.2,1.8l-0.2,1l0.4,0.1l0.3,0.5
l1.3,1.1h0.5h2h0.7l-1-5c-0.1-0.4-0.1-1.1,0-1.5l1.1-4.5l-0.6-0.5l-0.7-0.8v-0.6c0-0.7,1.4-1.3,1.8-1.8l1.1-0.3l0-0.9l-0.6-0.3
l-0.2-0.2l-3.7-2.5c-0.4-0.3-0.8-0.7-1-1.2l-1.9-3.1c-0.1-0.3-0.8-0.6-0.8-1v-1.6l0.2-2.3l-1.1-2c-0.2-0.2-0.1-0.5-0.2-0.7l-0.9-1.9
c-0.1-0.3-0.3-0.5-0.3-0.8v-0.3l-2.1-0.9c-0.3-0.1-0.4,0.5-0.6,0.3l-0.3,0.6h-2.8l0.8,2c0.2,0.9-0.1,1.6-0.8,2.3l-5.3,4.8l3.4,3
C225.2,536.1,225.4,536.3,225.5,536.6z"/>
</svg>
答案 0 :(得分:2)
你忽略了一个非常有意义的区别:
在 org.svg 中,svg
没有名称空间。
在 ill.svg 中,svg
位于http://www.w3.org/2000/svg
名称空间中。
为了对 ill.sgv 使用XPath,您必须执行以下操作之一:
声明并使用名称空间前缀(最好)。 [Credit:Daniel Haley]
xmllint --shell ill.svg
/ > setns s=http://www.w3.org/2000/svg
/ > xpath /s:svg
编写XPath,以便忽略命名空间。
xmllint --xpath "/*[local-name() = 'svg']" ill.svg