Having problems reading in an XML doc and parsing it.

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Alright, this is driving me nuts!!
I have the following XML document:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <?<span style="color:#A31515; xml <span style="color:Red; version<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1.0<span style="color:Black; " <span style="color:Red; encoding<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; UTF-16<span style="color:Black; "<span style="color:Blue; ?>
<span style="color:Blue; <<span style="color:#A31515; Task <span style="color:Red; version<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1.2<span style="color:Black; " <span style="color:Red; xmlns<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; http://schemas.microsoft.com/windows/2004/02/mit/task<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; RegistrationInfo<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Date<span style="color:Blue; >2011-02-18T16:55:19.3857935<span style="color:Blue; </<span style="color:#A31515; Date<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Author<span style="color:Blue; >SL510-THINKSL510<span style="color:Blue; </<span style="color:#A31515; Author<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Description<span style="color:Blue; >Tries to reconnect the BT on the VM<span style="color:Blue; </<span style="color:#A31515; Description<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; RegistrationInfo<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Triggers<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; EventTrigger<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Enabled<span style="color:Blue; >true<span style="color:Blue; </<span style="color:#A31515; Enabled<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Subscription<span style="color:Blue; ><span style="color:Red; &lt;QueryList<span style="color:Red; &gt;<span style="color:Red; &lt;Query Id="0" Path="System"<span style="color:Red; &gt;<span style="color:Red; &lt;Select Path="System"<span style="color:Red; &gt;*[System[Provider[@Name=Microsoft-Windows-Power-Troubleshooter] and EventID=1]]<span style="color:Red; &lt;/Select<span style="color:Red; &gt;<span style="color:Red; &lt;/Query<span style="color:Red; &gt;<span style="color:Red; &lt;/QueryList<span style="color:Red; &gt;<span style="color:Blue; </<span style="color:#A31515; Subscription<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; EventTrigger<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Triggers<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Principals<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Principal <span style="color:Red; id<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Author<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; RunLevel<span style="color:Blue; >LeastPrivilege<span style="color:Blue; </<span style="color:#A31515; RunLevel<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; UserId<span style="color:Blue; >SL510-THINKSL510<span style="color:Blue; </<span style="color:#A31515; UserId<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; LogonType<span style="color:Blue; >InteractiveToken<span style="color:Blue; </<span style="color:#A31515; LogonType<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Principal<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Principals<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Settings<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; MultipleInstancesPolicy<span style="color:Blue; >IgnoreNew<span style="color:Blue; </<span style="color:#A31515; MultipleInstancesPolicy<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; DisallowStartIfOnBatteries<span style="color:Blue; >true<span style="color:Blue; </<span style="color:#A31515; DisallowStartIfOnBatteries<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; StopIfGoingOnBatteries<span style="color:Blue; >true<span style="color:Blue; </<span style="color:#A31515; StopIfGoingOnBatteries<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; AllowHardTerminate<span style="color:Blue; >true<span style="color:Blue; </<span style="color:#A31515; AllowHardTerminate<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; StartWhenAvailable<span style="color:Blue; >false<span style="color:Blue; </<span style="color:#A31515; StartWhenAvailable<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; RunOnlyIfNetworkAvailable<span style="color:Blue; >false<span style="color:Blue; </<span style="color:#A31515; RunOnlyIfNetworkAvailable<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; IdleSettings<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; StopOnIdleEnd<span style="color:Blue; >true<span style="color:Blue; </<span style="color:#A31515; StopOnIdleEnd<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; RestartOnIdle<span style="color:Blue; >false<span style="color:Blue; </<span style="color:#A31515; RestartOnIdle<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; IdleSettings<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; AllowStartOnDemand<span style="color:Blue; >true<span style="color:Blue; </<span style="color:#A31515; AllowStartOnDemand<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Enabled<span style="color:Blue; >true<span style="color:Blue; </<span style="color:#A31515; Enabled<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Hidden<span style="color:Blue; >false<span style="color:Blue; </<span style="color:#A31515; Hidden<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; RunOnlyIfIdle<span style="color:Blue; >false<span style="color:Blue; </<span style="color:#A31515; RunOnlyIfIdle<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; WakeToRun<span style="color:Blue; >false<span style="color:Blue; </<span style="color:#A31515; WakeToRun<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; ExecutionTimeLimit<span style="color:Blue; >P3D<span style="color:Blue; </<span style="color:#A31515; ExecutionTimeLimit<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Priority<span style="color:Blue; >7<span style="color:Blue; </<span style="color:#A31515; Priority<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Settings<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Actions <span style="color:Red; Context<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Author<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Exec<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Command<span style="color:Blue; >"c:windowsSystem32WindowsPowerShellv1.0powershell.exe"<span style="color:Blue; </<span style="color:#A31515; Command<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Arguments<span style="color:Blue; >-ExecutionPolicy RemoteSigned -File "C:WakeFromSleep.ps1"<span style="color:Blue; </<span style="color:#A31515; Arguments<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Exec<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Actions<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Task<span style="color:Blue; >

[/code]
I need to change the Author and UserId to the current user. So here is my code:
<div style="color:Black;background-color:White; <pre>
<span style="color:OrangeRed; $restartBT <span style="color:Gray; = <span style="color:#A31515; "restartBT.xml"
<span style="color:OrangeRed; $xmlDoc <span style="color:Gray; = New<span style="color:Gray; -Object Xml.XmlDocument
<span style="color:OrangeRed; $xmlDoc.LoadXml(<span style="color:OrangeRed; $restartBT)
<span style="color:OrangeRed; $xmlNav <span style="color:Gray; = <span style="color:OrangeRed; $xmlDoc.CreateNavigator()
<span style="color:OrangeRed; $compUserName <span style="color:Gray; = <span style="color:OrangeRed; $env:computerName <span style="color:Gray; + <span style="color:#A31515; "" <span style="color:Gray; + <span style="color:OrangeRed; $env:userName
<span style="color:OrangeRed; $xmlNav.SelectSingleNode(<span style="color:#A31515; "/Task/RegistrationInfo/Author").InnerXML <span style="color:Gray; = <span style="color:OrangeRed; $compUserName
<span style="color:OrangeRed; $xmlNav.SelectSingleNode(<span style="color:#A31515; "//UserId").InnerXML <span style="color:Gray; = <span style="color:OrangeRed; $compUserName
<span style="color:OrangeRed; $xmlDoc.InnerXml

[/code]
But it isnt working. It wont find anything except the root node:
<div style="color:Black;background-color:White; <pre>
<span style="color:OrangeRed; $xmlNav.SelectSingleNode(<span style="color:#A31515; "/") <span style="color:Green; # works
<span style="color:OrangeRed; $xmlNav.SelectSingleNode(<span style="color:#A31515; "//Author") <span style="color:Green; # doesnt work

[/code]
I think this might have something to do with namespaces, but Im not entirly sure. Any help would be appreciated.

A <hr class="sig Adrian

View the full article
 
Back
Top