【发布时间】:2021-02-28 20:43:07
【问题描述】:
这是我的 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”
我尝试了以下命令:
-
xmllint --xpath "string(//PlatformSection)" file1.xml
-
xmllint --xpath "string(//Environment)" file1.xml
但两者都返回空白。同样,我尝试了 Property 和 PropertySection 并得到空白响应。
【问题讨论】:
-
你试图做什么?什么不工作?
-
您在默认命名空间中搜索,但您的数据位于
http://schemas.dmtf.org/ovf/environment/1。