我正在使用 XML::LibXML(仅限于 v1.58)。感谢博罗丁在这篇文章中我正确地获得了PROPERTY NAME="Name"
if的值CLASSNAME="SharedGtTranslator"
。我还想要获取VALUE.OBJECT
包含上述内容的整个父元素,并将其输出到另一个 XML 文件。
因此,如果 XML 文件如下所示:
<CIM CIMVERSION="2.0" DTDVERSION="2.0">
<DECLARATION>
<DECLGROUP>
<LOCALNAMESPACEPATH>
<NAMESPACE NAME="ecm"/>
</LOCALNAMESPACEPATH>
<!-- Ecm -->
<VALUE.OBJECT>
<INSTANCE CLASSNAME="Ecm">
<PROPERTY NAME="FileName" TYPE="string">
<VALUE>/opt/sign/log/ecm.log</VALUE>
</PROPERTY>
<PROPERTY NAME="Log" TYPE="sint32">
<VALUE>0</VALUE>
</PROPERTY>
<PROPERTY NAME="Name" TYPE="string">
<VALUE>ECM</VALUE>
</PROPERTY>
<PROPERTY NAME="TimerClaim" TYPE="sint32">
<VALUE>5000</VALUE>
</PROPERTY>
<PROPERTY NAME="TimerConnect" TYPE="sint32">
<VALUE>8000</VALUE>
</PROPERTY>
<PROPERTY NAME="TimerNegotiate" TYPE="sint32">
<VALUE>5000</VALUE>
</PROPERTY>
<PROPERTY NAME="TimerReconnect" TYPE="sint32">
<VALUE>500</VALUE>
</PROPERTY>
</INSTANCE>
</VALUE.OBJECT>
<VALUE.OBJECT>
<INSTANCE CLASSNAME="Ecm_Host">
<PROPERTY.REFERENCE NAME="Parent">
<VALUE.REFERENCE>
<INSTANCENAME CLASSNAME="Ecm">
<KEYBINDING NAME="Name">
<KEYVALUE>ECM</KEYVALUE>
</KEYBINDING>
</INSTANCENAME>
</VALUE.REFERENCE>
</PROPERTY.REFERENCE>
<PROPERTY.REFERENCE NAME="Child">
<VALUE.REFERENCE>
<INSTANCENAME CLASSNAME="Host">
<KEYBINDING NAME="Address">
<KEYVALUE>gtttcnss7v19</KEYVALUE>
</KEYBINDING>
</INSTANCENAME>
</VALUE.REFERENCE>
</PROPERTY.REFERENCE>
</INSTANCE>
</VALUE.OBJECT>
<VALUE.OBJECT>
<INSTANCE CLASSNAME="Ecm_ProcessClass">
<PROPERTY.REFERENCE NAME="Parent">
<VALUE.REFERENCE>
<INSTANCENAME CLASSNAME="Ecm">
<KEYBINDING NAME="Name">
<KEYVALUE>ECM</KEYVALUE>
</KEYBINDING>
</INSTANCENAME>
</VALUE.REFERENCE>
</PROPERTY.REFERENCE>
<PROPERTY.REFERENCE NAME="Child">
<VALUE.REFERENCE>
<INSTANCENAME CLASSNAME="ProcessClass">
<KEYBINDING NAME="ClassID">
<KEYVALUE>3</KEYVALUE>
</KEYBINDING>
</INSTANCENAME>
</VALUE.REFERENCE>
</PROPERTY.REFERENCE>
</INSTANCE>
</VALUE.OBJECT>
<VALUE.OBJECT>
<INSTANCE CLASSNAME="Ecm_ProcessClass">
<PROPERTY.REFERENCE NAME="Parent">
<VALUE.REFERENCE>
<INSTANCENAME CLASSNAME="Ecm">
<KEYBINDING NAME="Name">
<KEYVALUE>ECM</KEYVALUE>
</KEYBINDING>
</INSTANCENAME>
</VALUE.REFERENCE>
</PROPERTY.REFERENCE>
<PROPERTY.REFERENCE NAME="Child">
<VALUE.REFERENCE>
<INSTANCENAME CLASSNAME="ProcessClass">
<KEYBINDING NAME="ClassID">
<KEYVALUE>1</KEYVALUE>
</KEYBINDING>
</INSTANCENAME>
</VALUE.REFERENCE>
</PROPERTY.REFERENCE>
</INSTANCE>
</VALUE.OBJECT>
<VALUE.OBJECT>
<INSTANCE CLASSNAME="Ecm_ProcessClass">
<PROPERTY.REFERENCE NAME="Parent">
<VALUE.REFERENCE>
<INSTANCENAME CLASSNAME="Ecm">
<KEYBINDING NAME="Name">
<KEYVALUE>ECM</KEYVALUE>
</KEYBINDING>
</INSTANCENAME>
</VALUE.REFERENCE>
</PROPERTY.REFERENCE>
<PROPERTY.REFERENCE NAME="Child">
<VALUE.REFERENCE>
<INSTANCENAME CLASSNAME="ProcessClass">
<KEYBINDING NAME="ClassID">
<KEYVALUE>15</KEYVALUE>
</KEYBINDING>
</INSTANCENAME>
</VALUE.REFERENCE>
</PROPERTY.REFERENCE>
</INSTANCE>
</VALUE.OBJECT>
<VALUE.OBJECT>
<INSTANCE CLASSNAME="SharedGtTranslator">
<QUALIFIER NAME="Configstate" TYPE="string">
<VALUE>planned</VALUE>
</QUALIFIER>
<PROPERTY NAME="Name" TYPE="string">
<VALUE>HLR$4,0,1,3,7240*-->HLR HLR LocalSPC: 410 SSN: 6</VALUE>
</PROPERTY>
<PROPERTY NAME="NatureOfAddress" TYPE="sint32">
<VALUE>3</VALUE>
</PROPERTY>
<PROPERTY NAME="NetworkID" TYPE="sint32">
<VALUE>1</VALUE>
</PROPERTY>
<PROPERTY NAME="NumberSeries" TYPE="sint32">
<VALUE>7240*</VALUE>
</PROPERTY>
<PROPERTY NAME="NumberingPlan" TYPE="sint32">
<VALUE>1</VALUE>
</PROPERTY>
<PROPERTY NAME="TranslationType" TYPE="sint32">
<VALUE>0</VALUE>
</PROPERTY>
</INSTANCE>
</VALUE.OBJECT>
<VALUE.OBJECT>
<INSTANCE CLASSNAME="SharedGtTranslator">
<QUALIFIER NAME="Configstate" TYPE="string">
<VALUE>planned</VALUE>
</QUALIFIER>
<PROPERTY NAME="Name" TYPE="string">
<VALUE>HLR$4,0,1,3,7250*-->HLR HLR LocalSPC: 410 SSN: 6</VALUE>
</PROPERTY>
<PROPERTY NAME="NatureOfAddress" TYPE="sint32">
<VALUE>3</VALUE>
</PROPERTY>
<PROPERTY NAME="NetworkID" TYPE="sint32">
<VALUE>1</VALUE>
</PROPERTY>
<PROPERTY NAME="NumberSeries" TYPE="sint32">
<VALUE>7250*</VALUE>
</PROPERTY>
<PROPERTY NAME="NumberingPlan" TYPE="sint32">
<VALUE>1</VALUE>
</PROPERTY>
<PROPERTY NAME="TranslationType" TYPE="sint32">
<VALUE>0</VALUE>
</PROPERTY>
</INSTANCE>
</VALUE.OBJECT>
</DECLGROUP>
</DECLARATION>
</CIM>
新文件将仅包含以下内容:
<CIM>
<DECLARATION>
<DECLGROUP>
<VALUE.OBJECT>
<INSTANCE CLASSNAME="SharedGtTranslator">
<QUALIFIER NAME="Configstate" TYPE="string">
<VALUE>planned</VALUE>
</QUALIFIER>
<PROPERTY NAME="Name" TYPE="string">
<VALUE>HLR$4,0,1,3,7240*-->HLR HLR LocalSPC: 410 SSN: 6</VALUE>
</PROPERTY>
<PROPERTY NAME="NatureOfAddress" TYPE="sint32">
<VALUE>3</VALUE>
</PROPERTY>
<PROPERTY NAME="NetworkID" TYPE="sint32">
<VALUE>1</VALUE>
</PROPERTY>
<PROPERTY NAME="NumberSeries" TYPE="sint32">
<VALUE>7240*</VALUE>
</PROPERTY>
<PROPERTY NAME="NumberingPlan" TYPE="sint32">
<VALUE>1</VALUE>
</PROPERTY>
<PROPERTY NAME="TranslationType" TYPE="sint32">
<VALUE>0</VALUE>
</PROPERTY>
</INSTANCE>
</VALUE.OBJECT>
<VALUE.OBJECT>
<INSTANCE CLASSNAME="SharedGtTranslator">
<QUALIFIER NAME="Configstate" TYPE="string">
<VALUE>planned</VALUE>
</QUALIFIER>
<PROPERTY NAME="Name" TYPE="string">
<VALUE>HLR$4,0,1,3,7250*-->HLR HLR LocalSPC: 410 SSN: 6</VALUE>
</PROPERTY>
<PROPERTY NAME="NatureOfAddress" TYPE="sint32">
<VALUE>3</VALUE>
</PROPERTY>
<PROPERTY NAME="NetworkID" TYPE="sint32">
<VALUE>1</VALUE>
</PROPERTY>
<PROPERTY NAME="NumberSeries" TYPE="sint32">
<VALUE>7250*</VALUE>
</PROPERTY>
<PROPERTY NAME="NumberingPlan" TYPE="sint32">
<VALUE>1</VALUE>
</PROPERTY>
<PROPERTY NAME="TranslationType" TYPE="sint32">
<VALUE>0</VALUE>
</PROPERTY>
</INSTANCE>
</VALUE.OBJECT>
</DECLGROUP>
</DECLARATION>
</CIM>