將php腳本移植到golang時出現問題。在golang中收集具有給定名稱的所有xml結構體
是否有golang類似PHP的任何方法:
$processRefList = $faceContainer->getElementsByTagName('processRef');
有一個名爲processRef
嵌套元素的數量龐大的XML文件。
所以我需要收集所有這些元素而不處理嵌套結構樹。
這裏XML的例子部分:
<face>
<processes>
<process group="1" type="regular"/>
<process group="2" type="spotUV" state="off"/>
</processes>
<assets>...</assets>
<groups>
<group id="1">
<assetRefs>
<imageRef ref="1" x="0" y="0" id="8">
<processRefs>
<!-- This applies spotUV to this asset and removes the regular process. -->
<processRef ref="1" state="off"/>
<processRef ref="2" state="on"/>
</processRefs>
</imageRef>
<textRef ref="1" x="161" y="41" id="7"/>
<textRef ref="2" x="160" y="55" id="6">
<processRefs>
<!-- This applies spotUV to this asset and also leaves regular process applied. -->
<processRef ref="2" state="on"/>
</processRefs>
</textRef>
</assetRefs>
</group>
<group id="2">...</group>
</groups>
這可能會有幫助。 http://blog.labix.org/2013/06/07/efficient-xpath-for-go – 2015-03-31 15:25:56