【发布时间】:2017-09-28 20:54:53
【问题描述】:
几天来,我一直在尝试弄清楚如何使它工作(我最终陷入了再次查看相同文章的循环,因为您已经在谷歌上搜索了很多问题的组合)
我看过Read XML in VB.net 和How to read an XML File 和How to read XML elements in VB.NET 和Retrieve single attribute value from an xml doc element 其中最后一个似乎指向我正确的方向,但是在运行DWRoelands 指定的代码时,我收到“System.Collections.Generic.List`1[ System.String]" 到控制台输出。
请参阅下面的 XML,我需要从 /Files/File/Link 元素中的 HREF 属性中提取 https://server/transfer/descriptor.ovf,并且仅适用于列为 descriptor.ovf 的文件(我运行的第二个 XML 文件有另一个文件为 VMDK 列出)
谢谢
XML 片段:
<?xml version="1.0" encoding="UTF-8"?>
<VApp href="https://#####/api/vApp/vapp-##">
<Link rel="down"/>
<Description>Test vAPP</Description>
<Tasks>
<Task cancelRequested="false" >
<Link rel="task:cancel" />
<Progress>1</Progress>
<Details/>
</Task>
</Tasks>
<Files>
<File bytesTransferred="0" size="-1" name="descriptor.ovf">
<Link rel="upload:default" href="https://server/transfer/descriptor.ovf"/>
</File>
</Files>
<InMaintenanceMode>false</InMaintenanceMode>
</VApp>
整个 XML:
<?xml version="1.0" encoding="UTF-8"?>
<VApp xmlns="http://www.vmware.com/vcloud/v1.5" ovfDescriptorUploaded="false" deployed="false" status="0" name="Test vAPP" id="urn:vcloud:vapp:#####" href="https://server/api/vApp/vapp-#####" type="application/vnd.vmware.vcloud.vApp+xml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 https://server/api/v1.5/schema/master.xsd">
<Link rel="down" href="https://server/api/vApp/vapp-#####/controlAccess/" type="application/vnd.vmware.vcloud.controlAccess+xml"/>
<Link rel="up" href="https://server/api/vdc/#####" type="application/vnd.vmware.vcloud.vdc+xml"/>
<Link rel="down" href="https://server/api/vApp/vapp-#####/owner" type="application/vnd.vmware.vcloud.owner+xml"/>
<Link rel="down" href="https://server/api/vApp/vapp-#####/metadata" type="application/vnd.vmware.vcloud.metadata+xml"/>
<Link rel="ovf" href="https://server/api/vApp/vapp-#####/ovf" type="text/xml"/>
<Link rel="down" href="https://server/api/vApp/vapp-#####/productSections/" type="application/vnd.vmware.vcloud.productSections+xml"/>
<Description>Test vAPP</Description>
<Tasks>
<Task cancelRequested="false" expiryTime="2017-07-30T11:02:07.457+08:00" operation="Importing Virtual Application Test vAPP(#####)" operationName="vdcUploadOvfContents" serviceNamespace="com.vmware.vcloud" startTime="2017-05-01T11:02:07.457+08:00" status="running" name="task" id="urn:vcloud:task:######" href="https://server/api/task/####" type="application/vnd.vmware.vcloud.task+xml">
<Link rel="task:cancel" href="https://server/api/task/#####/action/cancel"/>
<Owner href="https://server/api/vApp/vapp-#####" name="Test vAPP" type="application/vnd.vmware.vcloud.vApp+xml"/>
<User href="https://server/api/admin/user/####" name="#####" type="application/vnd.vmware.admin.user+xml"/>
<Organization href="https://server/api/org/#####" name="#####" type="application/vnd.vmware.vcloud.org+xml"/>
<Progress>1</Progress>
<Details/>
</Task>
</Tasks>
<Files>
<File bytesTransferred="0" size="-1" name="descriptor.ovf">
<Link rel="upload:default" href="https://server/transfer/#####/descriptor.ovf"/>
</File>
</Files>
<DateCreated>2017-05-01T11:02:07.417+08:00</DateCreated>
<Owner type="application/vnd.vmware.vcloud.owner+xml">
<User href="https://server/api/admin/user/#####" name="#####" type="application/vnd.vmware.admin.user+xml"/>
</Owner>
<InMaintenanceMode>false</InMaintenanceMode>
</VApp>
【问题讨论】: