这是我的XML文件
<?xml version="1.0" encoding="UTF-8"?>
<Environment xmlns="http://schemas.dmtf.org/ovf/environment/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:oe="http://schemas.dmtf.org/ovf/environment/1" xmlns:ve="http://www.vmware.com/schema/ovfenv" oe:id="" ve:vCenterId="">
<PlatformSection>
<Kind>VMware ESXi</Kind>
<Version>7.0.0</Version>
<Vendor>VMware, Inc.</Vendor>
<Locale>en</Locale>
</PlatformSection>
<PropertySection>
<Property oe:key="test" oe:value="test123"/>
<Property oe:key="testing" oe:value="testing123"/>
</PropertySection>
<ve:EthernetAdapterSection>
<ve:Adapter ve:mac="" ve:network="" ve:unitNumber="7"/>
</ve:EthernetAdapterSection>
</Environment>我想使用XMLLint解析它,并获取所有"oe:key“和"oe:value”
我尝试了以下命令:
但两个人都是空白的。类似地,我尝试了属性和PropertySection,并得到了一个空白的响应。
发布于 2020-11-17 15:58:00
输入XML包含名称空间。所有元素都绑定到以下名称空间:xmlns:oe="http://schemas.dmtf.org/ovf/environment/1"
请尝试以下XPath:
/oe:Environment/oe:PlatformSection或
/oe:Environment/oe:PropertySection/oe:Property/@oe:key或尝试名称空间通配符方法
/*[local-name()='Environment']/*[local-name()='PlatformSection']获取第一个oe:key属性
/*[local-name()='Environment']/*[local-name()='PropertySection']/*[local-name()='Property'][1]/@oe:key获取所有属性
/*[local-name()='Environment']/*[local-name()='PropertySection']/*[local-name()='Property'][1]/@*这里还概述了另一种方法:用于XML命名空间的xmllint
https://stackoverflow.com/questions/64878545
复制相似问题