【发布时间】:2019-05-10 16:13:28
【问题描述】:
如何使用 PowerShell 读取 XML 文件并从具有大量标签的文件中提取数据?我正在使用以下代码提取标签,但无法从子标签中读取数据。
$xmlFile= "D:\Testing\TestcasesOutput\1ac.xml"
$xmlConfig = [System.Xml.XmlDocument](Get-Content $xmlFile)
$XmlDocument.Breakfast_menu.price
我希望输出读取整个 xml 文件,但无法读取整个 xml 文件。
<?xml version="1.0" encoding="UTF-8"?>
<breakfast_menu>
<food>
<food>Belgian Waffles</food>
<price>$5.95</price>
<description>Two of our famous Belgian Waffles with plenty of real maple
syrup</description>
<calories>650</calories>
</food>
<food>
<food>Strawberry Belgian Waffles</food>
<price>$7.95</price>
<description>Light Belgian waffles covered with strawberries and whipped
cream</description>
<calories>900</calories>
</food>
<food>
<food>Berry-Berry Belgian Waffles</food>
<price>$8.95</price>
<description>Light Belgian waffles covered with an assortment of fresh
berries and whipped cream</description>
<calories>900</calories>
</food>
<food>
<food>French Toast</food>
<price>$4.50</price>
<description>Thick slices made from our homemade sourdough
bread</description>
<calories>600</calories>
</food>
<food>
<food>Homestyle Breakfast</food>
<price>$6.95</price>
<description>Two eggs, bacon or sausage, toast, and our ever-popular hash
browns</description>
<calories>950</calories>
</food>
</breakfast_menu>
【问题讨论】:
-
我正在使用下面的代码来提取早餐菜单标签,但无法从早餐菜单子标签中读取数据。 $xmlFile= "D:\Testing\TestcasesOutput\1ac.xml" $xmlConfig = [System.Xml.XmlDocument](Get-Content $xmlFile) $XmlDocument.Breakfast_menu.price
-
不要评论你自己的问题,而是将这些重要的行附加到它上面。
-
请edit您的问题并将xml(的相关部分)放在那里。接下来,同上@quantummind cmets
-
@Theo
比利时华夫饼 $5.95 两个我们著名的比利时华夫饼配大量真正的枫糖浆 650 -
恐怕这不是一个诺诺。如评论所述,单击您的问题下方的
edit,然后将信息放入formatted way。切勿在评论中粘贴重要信息或代码,因为这很快就会变得难以阅读。
标签: xml powershell