Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 使用基于Powershell的关闭条件更改XML中的标签_.net_Xml_Powershell_Loops - Fatal编程技术网

.net 使用基于Powershell的关闭条件更改XML中的标签

.net 使用基于Powershell的关闭条件更改XML中的标签,.net,xml,powershell,loops,.net,Xml,Powershell,Loops,示例XML文件: <?xml version="1.0" encoding="utf-8"?> <Searchable xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" label="$RESX('Bank.1_8','CRDM_AgeInformation','Age Information')" xmlns="http://sy

示例XML文件:

<?xml version="1.0" encoding="utf-8"?>
<Searchable xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" label="$RESX('Bank.1_8','CRDM_AgeInformation','Age Information')" xmlns="http://sysrepublic.com/Secure/4.0/DSL/SearchService">
  <Parameters />
  <Fields>
    <Field data-type="System.Int64" is-editable="true" id="ageinformation_transactionid" label="$RESX('Bank.1_8','TransactionID','Transaction ID')" is-mandatory-display-field="false" is-hidden-display-field="false" is-virtual-date-time="false" is-display-field-only="false" use-utc-datetime="true" apply-user-timezone-offset="false" show-date="true" show-time="true" is-favourite="false" common-field="true">
      <FieldDescription primary-key="false" nullable="false" readonly="false" hidden="false" format="text" enable-required-validation="true" />
      <Operators>
        <Operator name="equal" />
        <Operator name="notequal" />
        <Operator name="greaterthan" />
        <Operator name="greaterthanequal" />
        <Operator name="lessthan" />
        <Operator name="lessthanequal" />
        <Operator name="between" />
        <Operator name="notbetween" />
        <Operator name="in" />
        <Operator name="notin" />
      </Operators>
      <LeftExpression>
        <Field data-type="System.Int64" common-field="true">
          <CollectionDescription collection="pos.CRDM_AgeInformation">
            <Relationship parent="pos.CRDM_Header">
              <RelatedField from="TransactionID" to="TransactionID" common-to-field="true" />
              <RelatedField from="TradingDay" to="TradingDay" common-to-field="true" />
            </Relationship>
          </CollectionDescription>
          <Description>TransactionID</Description>
        </Field>
      </LeftExpression>
    </Field>
    <Field data-type="System.Int64" is-editable="true" id="ageinformation_checkpointid" label="$RESX('Bank.1_8','CheckPointID','CheckPoint ID')" is-mandatory-display-field="false" is-hidden-display-field="false" is-virtual-date-time="false" is-display-field-only="false" use-utc-datetime="true" apply-user-timezone-offset="false" show-date="true" show-time="true" is-favourite="false">
      <FieldDescription primary-key="false" nullable="false" readonly="false" hidden="false" format="text" enable-required-validation="true" />
      <Operators>
        <Operator name="equal" />
        <Operator name="notequal" />
        <Operator name="greaterthan" />
        <Operator name="greaterthanequal" />
        <Operator name="lessthan" />
        <Operator name="lessthanequal" />
        <Operator name="between" />
        <Operator name="notbetween" />
        <Operator name="in" />
        <Operator name="notin" />
      </Operators>
      <LeftExpression>
        <Field data-type="System.Int64">
          <CollectionDescription collection="pos.CRDM_AgeInformation">
            <Relationship parent="pos.CRDM_Header">
              <RelatedField from="TransactionID" to="TransactionID" common-to-field="true" />
              <RelatedField from="TradingDay" to="TradingDay" common-to-field="true" />
            </Relationship>
          </CollectionDescription>
          <Description>CheckPointID</Description>
        </Field>
      </LeftExpression>
    </Field>

</Fields>
</Searchable>
在调试代码时显示,我无法正确更新标签。有人能提出改变这种状况的最佳方法吗。在运行代码时,我没有看到$node.label打印出来

问题

  • 在我的输出中看不到$node.description打印(已解决)
  • 在IF块中更新$node.label后,看不到打印出来的$node.label

  • 以下是应如何编写IF块:

    if($Resource -match '0'){
            $mid_value = $id -replace "_","."
            $new_label = "$RESX(Ebr.Crdm.Store.2_0,"+$mid_value+","+$description+")"
            $node.label = $new_label
            Write-Output("The updated label is"+$node.label)
    
            $b = $node.label
            $b -match $regex
            $newdata = $Matches[1]
            $y = $newdata.split(',')
            Write-Output("The first updated element of the node label is"+" "+$y[0])
            Write-Output("The second updated element of the node label is"+" "+$y[1])
            Write-Output("The third updated element of the node label is"+" "+$y[2])
            $insert_query = "INSERT INTO [Secure4].[secure].[Resource]
                   ([ResourceType],[CultureCode],[ResourceKey],[ResourceValue])
                   VALUES
                        ('"+$y[0]+"','en','"+$y[1]+"','"+$y[2]+"')"
            Write-Output($insert_query)
             $Resource2 = (Invoke-SQLCmd -query $insert_query -Server $SQLServer) 
             #write-output($Resource2)
    
        }
    

    @vonPryz我把它写得简短一些,让它更清楚。请看一看,如果您有任何建议,请告诉我。我似乎没有正确引用描述变量,这很可能是导致错误的原因issue@JamesZ谢谢你编辑我的问题。编辑看起来非常好,我已经找到了引用它的正确方法:“$nodes=$xml.Searchable.Fields.Field.LeftExpression.Field”,这意味着我必须对循环进行更改
    if($Resource -match '0'){
            $mid_value = $id -replace "_","."
            $new_label = "$RESX(Ebr.Crdm.Store.2_0,"+$mid_value+","+$description+")"
            $node.label = $new_label
            Write-Output("The updated label is"+$node.label)
    
            $b = $node.label
            $b -match $regex
            $newdata = $Matches[1]
            $y = $newdata.split(',')
            Write-Output("The first updated element of the node label is"+" "+$y[0])
            Write-Output("The second updated element of the node label is"+" "+$y[1])
            Write-Output("The third updated element of the node label is"+" "+$y[2])
            $insert_query = "INSERT INTO [Secure4].[secure].[Resource]
                   ([ResourceType],[CultureCode],[ResourceKey],[ResourceValue])
                   VALUES
                        ('"+$y[0]+"','en','"+$y[1]+"','"+$y[2]+"')"
            Write-Output($insert_query)
             $Resource2 = (Invoke-SQLCmd -query $insert_query -Server $SQLServer) 
             #write-output($Resource2)
    
        }