![](/img/trans.png)
[英]selectNodes function of ActiveXObject does not work in IE 11
[英]Powershell: Using a variable inside SelectNodes does not work
我想在 SelectNodes 命令中使用一個變量。 不幸的是,它不起作用:( XML 的內容是德語,對此感到抱歉。
Write-Output $propName
$propertyValue= $inputFile.SelectNodes("/MatML_Doc/Material/BulkDetails/PropertyData[@property='$propName']/Data")
Write-Output 給了我字符串“Bruchdehnung”。 但是 $propertyValue 是空的。
當我將 SelectNodes 命令中的 $propName 替換為“Bruchdehnung”時,它按預期工作。
$propertyValue= $inputFile.SelectNodes("/MatML_Doc/Material/BulkDetails/PropertyData[@property='Bruchdehnung']/Data")
這是 XML 文件:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<MatML_Doc>
<Material>
<BulkDetails>
<Notes/>
<Name>1.0037 (St37)</Name>
<Class>
<Name>METAL|Steel</Name>
</Class>
<Source source=""/>
<ExternalIdentifier>1.0037 (St37)</ExternalIdentifier>
<PropertyData property="Bruchdehnung">
<Data format="exponential">0.000000e+000</Data>
</PropertyData>
<PropertyData property="Dichte">
<Data format="exponential">7.800000e+003</Data>
</PropertyData>
<PropertyData property="Elastizitätsmodul">
<Data format="exponential">2.100000e+011</Data>
</PropertyData>
<PropertyData property="Material Type">
<Data format="string">IsotropicMaterial</Data>
</PropertyData>
<PropertyData property="Poissonscher Beiwert">
<Data format="exponential">2.800000e-001</Data>
</PropertyData>
<PropertyData property="Spezifische Wärme">
<Data format="exponential">4.400000e+002</Data>
</PropertyData>
<PropertyData property="Streckgrenze">
<Data format="exponential">2.350000e+008</Data>
</PropertyData>
<PropertyData property="Wärmeausdehnungskoef.">
<Data format="exponential">1.100000e-005</Data>
</PropertyData>
<PropertyData property="Wärmeleitfähigkeit">
<Data format="exponential">1.400000e+001</Data>
</PropertyData>
<PropertyData property="Zugfestigkeit">
<Data format="exponential">3.600000e+008</Data>
</PropertyData>
</BulkDetails>
</Material>
你知道為什么我不能在 SelectNodes 命令中使用變量嗎?
感謝大家的幫助:我找到了解決方案:
$propertyValue= $inputFile.SelectNodes("/MatML_Doc/Material/BulkDetails/PropertyData[@property='$propName.Value']/Data")
我無法直接讀取 XML object。 我必須使用.Value 來獲取實際值:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.