PC Review


Reply
Thread Tools Rate Thread

How to change value of element with known path using XML

 
 
=?Utf-8?B?VG9uZQ==?=
Guest
Posts: n/a
 
      26th Feb 2007
Hi,

I need to change a value of an element in an XML file, I have been trying to
select the node to edit but can only get as far as component and have to
itterate through..

XmlDocument doc = new XmlDocument();
doc.Load("C:\\WINDOWS\\Panther\\Sysprep.xml");

// Create an XmlNamespaceManager to resolve the default namespace.
XmlNamespaceManager nsmgr = new
XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("bk", "urn:schemas-microsoft-com:unattend");

// Select and display all book titles.
XmlNodeList nodeList;
XmlElement root = doc.DocumentElement;
nodeList =
root.SelectNodes("/bk:unattend/bk:settings/bk:component", nsmgr);

Is it possible to select the computername element directly to edit or get to
the "settings pass="specialize" node?

nodeList =
root.SelectNodes("/bk:unattend/bk:settings/bk:component/bk:component
name="Microsoft-Windows-Shell-Setup" processorArchitecture="x86"
publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"
xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/bk:settings
pass="specialize"/bk:ComputerName", nsmgr);


sysprep.xml

<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
<settings pass="oobeSystem">
<component name="Microsoft-Windows-Shell-Setup"
processorArchitecture="x86" publicKeyToken="31bf3856ad364e35"
language="neutral" versionScope="nonSxS"
xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<FirstLogonCommands>
<SynchronousCommand wcm:action="add">
<Order>1</Order>
<CommandLine>net user administrator
/active:yes</CommandLine>
</SynchronousCommand>
</FirstLogonCommands>
<OOBE>
<NetworkLocation>Work</NetworkLocation>
<HideEULAPage>true</HideEULAPage>
<SkipMachineOOBE>false</SkipMachineOOBE>
<SkipUserOOBE>true</SkipUserOOBE>
<ProtectYourPC>1</ProtectYourPC>
</OOBE>
<UserAccounts>
<AdministratorPassword>

<Value>aQBzAHQAbABhAGIAMgAxAEEAZABtAGkAbgBpAHMAdAByAGEAdABvAHIAUABhAHMAcwB3AG8AcgBkAA==</Value>
<PlainText>false</PlainText>
</AdministratorPassword>
</UserAccounts>
<VisualEffects>
<FontSmoothing>ClearType</FontSmoothing>
</VisualEffects>
</component>
</settings>
<settings pass="windowsPE">
<component name="Microsoft-Windows-Setup"
processorArchitecture="x86" publicKeyToken="31bf3856ad364e35"
language="neutral" versionScope="nonSxS"
xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<UserData>
<AcceptEula>true</AcceptEula>
<FullName>iststudent</FullName>
<Organization>Penn State</Organization>
</UserData>
<EnableFirewall>true</EnableFirewall>
<EnableNetwork>true</EnableNetwork>
<Restart>Restart</Restart>
<UseConfigurationSet>true</UseConfigurationSet>
</component>
</settings>
<settings pass="specialize">
<component name="Microsoft-Windows-UnattendedJoin"
processorArchitecture="x86" publicKeyToken="31bf3856ad364e35"
language="neutral" versionScope="nonSxS"
xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Identification>
<Credentials>
<Domain>testnet.com</Domain>

<PasswordaQBzAHQAbABhAGIAMgAxAEEAZABtAGkAbgBpAHMAdAByAGEAdABvAHIAUABhAHMAcwB3AG8AcgBkAA==</Password>
<Username>iststudent</Username>
</Credentials>
<JoinDomain>testnet.com</JoinDomain>
<UnsecureJoin></UnsecureJoin>
</Identification>
</component>
<component name="Microsoft-Windows-Shell-Setup"
processorArchitecture="x86" publicKeyToken="31bf3856ad364e35"
language="neutral" versionScope="nonSxS"
xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<DisableAutoDaylightTimeSet>false</DisableAutoDaylightTimeSet>
<RegisteredOrganization>Penn State</RegisteredOrganization>
<RegisteredOwner>iststudent</RegisteredOwner>
<TimeZone>Eastern Standard Time</TimeZone>
<ComputerName>Workstation_001</ComputerName>
</component>
</settings>
<settings pass="generalize">
<component name="Microsoft-Windows-PnpSysprep"
processorArchitecture="x86" publicKeyToken="31bf3856ad364e35"
language="neutral" versionScope="nonSxS"
xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<PersistAllDeviceInstalls>true</PersistAllDeviceInstalls>
</component>
</settings>
<cpifflineImage cpi:source="wim://ms001/distribition$/vista.wim#vista"
xmlns:cpi="urn:schemas-microsoft-com:cpi" />
</unattend>
 
Reply With Quote
 
 
 
 
=?Utf-8?B?VG9uZQ==?=
Guest
Posts: n/a
 
      27th Feb 2007
Post was probably a little unclear could someone tell me if its possible to
use selectnodes when node name have values, spaces etc..

this works --> root.SelectNodes("/bk:unattend/bk:settings/bk:component"

this doesnt --> root.SelectNodes("/bk:unattend/bk:settings/bk:component
name="Microsoft-Windows-Shell-Setup" processorArchitecture="x86"
publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"
xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

Thanks..
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Anchor element doesn't work with full path AAaron123 Microsoft ASP .NET 3 16th Mar 2009 02:22 AM
Change css element with C# Peter Microsoft ASP .NET 4 9th Apr 2008 09:48 PM
Element 'Element Name Here' is not a known element. This can occur if there is a compilation error in the Web M Noreen Microsoft Dot NET 3 17th Apr 2006 07:28 AM
Relative path for <value> of .resx data element (ResxFileRef) Ly Lam Microsoft Dot NET 0 5th Jul 2004 10:02 PM
How to set a default Path on a TextField Element? =?Utf-8?B?UGx1bmFsZG8=?= Microsoft ASP .NET 0 30th Mar 2004 10:31 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:14 AM.