locked
propertyValue "" = to [int]0 or "0" RRS feed

  • Question

  • Hello
    Pls, i would change the "propertyValue" "" = to [int]0 or "0"
    But i don't have any successe.
    
    Many thnx for you help
    My best regards
    Arnold
    
    ----------------------------
    <Obj RefId="51">
    <TNRef RefId="9"/>
    <ToString>Microsoft.PowerShell.Commands.Internal.Format.FormatPropertyField</ToString> 
    <Props>
    <S N="ClassId2e4f51ef21dd47e99d3c952918aff9cd">78b102e894f742aca8c1d6737b6ff86a</S>
    <S N="propertyValue"></S>
    <I32 N="alignment">0</I32>
    </Props>
    </Obj>
    
    
    cls
    $xmlstatistiqueBao = [xml](Get-Content C:\studio\interville\statistiqueBao.xml)
    $ObjNodestatistiqueBao = $xmlstatistiqueBao.Objs.GetElementsByTagName("Obj") | Where {[int]$_.RefId -ge 23 -and [int]$_.RefId -le 647}
    
    $nr = 1
    $filedata = Foreach($obj in $ObjNodestatistiqueBao)
     {
    	$obj.Props.S | Where-Object { $_.N -eq "propertyValue"} | % {if( $_."#text".length -eq [int]0) {$obj -replace "","0"}} | sort -Descending
    	$nr ++
     }
     
     $filedata
     " $nr "
     
     $xmlstatistiqueBao.Save("C:\studio\interville\statistiqueBao.xml")
    
    $ObjNodestatistiqueBao[27].Props.S[1]."#text"
    

    Thursday, November 10, 2011 4:21 PM

Answers

  • Hi Arnold,

    Try this:

    $xmlstatistiqueBao = [xml](Get-Content p:\test.xml)
    $ObjNodestatistiqueBao = $xmlstatistiqueBao.Objs.GetElementsByTagName("Obj") | Where {[int]$_.RefId -ge 23 -and [int]$_.RefId -le 647}
    $emptyS = $xmlstatistiqueBao.CreateTextNode("0")
    $nr = 1
    $filedata = Foreach($obj in $ObjNodestatistiqueBao)
     {
    	$obj.Props.S | Where-Object { $_.N -eq "propertyValue"} | % {if( $_."#text" -eq $null) {[void]$_.appendChild($emptyS)}} | sort -Descending
    	$nr ++
     }
    


     

    Thursday, November 10, 2011 5:32 PM
  • hello @Michal !

    Many thanks for you reply.

    I don't get any response "it is insensible".

    But i don't get any error.

     

    My best regard

    Arnold

    • Marked as answer by arnold_ Monday, November 21, 2011 9:12 PM
    Thursday, November 10, 2011 7:08 PM

All replies

  • you don’t need to do replace, also, the replace doesn’t assign the value, it
    just spits it out...
     
    ie, look at this
     
    $str = "hello"
    $str -replace "he","me"
    $str
     
    if you want to to change it you need to do this
     
    $str = $str -replace "he","me"
     
    but in your case you don’t even need to do that..
     
    the problem is that because there is nothing in there (as per the example
    you have) the #text doesn’t exist... look at the output of this..
     $x = [xml]@'
    <Obj RefId="51">
    <TNRef RefId="9"/>
    <ToString>Microsoft.PowerShell.Commands.Internal.Format.FormatPropertyField</ToString>
    <Props>
    <S
    N="ClassId2e4f51ef21dd47e99d3c952918aff9cd">78b102e894f742aca8c1d6737b6ff86a</S>
    <S N="propertyValue"></S>
    <I32 N="alignment">0</I32>
    </Props>
    </Obj>
    '@
     
    $x.Obj.Props.s
     
    $x.obj.props.s | ? {$_.n -eq "propertyvalue"}
     
    $x.obj.props.s | ? {$_.n -eq "propertyvalue"} | gm
     
    you'll see there is only one valid property, N, if you look for the other
    property like so
     
    $p.obj.props.s | ? {$_.n -eq "ClassId2e4f51ef21dd47e99d3c952918aff9cd"} | gm
     
    you'll see this has a #text
     
    so, you need to find ones that don’t have a #text, add it and set it to 0..
    not sure how you do that :)
     
     

    Justin Rich
    http://jrich523.wordpress.com
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Thursday, November 10, 2011 5:01 PM
  • Hi Arnold,

    Try this:

    $xmlstatistiqueBao = [xml](Get-Content p:\test.xml)
    $ObjNodestatistiqueBao = $xmlstatistiqueBao.Objs.GetElementsByTagName("Obj") | Where {[int]$_.RefId -ge 23 -and [int]$_.RefId -le 647}
    $emptyS = $xmlstatistiqueBao.CreateTextNode("0")
    $nr = 1
    $filedata = Foreach($obj in $ObjNodestatistiqueBao)
     {
    	$obj.Props.S | Where-Object { $_.N -eq "propertyValue"} | % {if( $_."#text" -eq $null) {[void]$_.appendChild($emptyS)}} | sort -Descending
    	$nr ++
     }
    


     

    Thursday, November 10, 2011 5:32 PM
  • Hi sir !
    
    Many thnx for your reply.
    
    I understand i't.
    
    So is'n i't not possible to change or add any array?
    
    The origine comm's from the txt file:
    @{Expression = {"{0: ## ### ###}" -f ([Int]$_.Recon)}; Label = "Connect."; Alignment = "right"},
    
    So i have to change the Expression!?
    
    Can i change the value from : "- 124 211 128" to "-124211128"		
    $objs.replace(" ","")? 
    
    My best regards
    Arnold
    

    Thursday, November 10, 2011 5:32 PM
  • hello @Michal !

    Many thanks for you reply.

    I don't get any response "it is insensible".

    But i don't get any error.

     

    My best regard

    Arnold

    • Marked as answer by arnold_ Monday, November 21, 2011 9:12 PM
    Thursday, November 10, 2011 7:08 PM