473,385 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to change value of element with known path using XML

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>aQBzAHQAbABhAGIAMgAxAEEAZABtAGkAbgBpAHMAdAB yAGEAdABvAHIAUABhAHMAcwB3AG8AcgBkAA==</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>

<PasswordaQBzAHQAbABhAGIAMgAxAEEAZABtAGkAbgBpAHMAd AByAGEAdABvAHIAUABhAHMAcwB3AG8AcgBkAA==</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>
<cpi:offlineImage cpi:source="wim://ms001/distribition$/vista.wim#vista"
xmlns:cpi="urn:schemas-microsoft-com:cpi" />
</unattend>
Feb 26 '07 #1
1 2458
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..
Feb 27 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Wim Roffal | last post by:
Is it possible to use javascript to change the name of a field in a form? Thanks, Wim
4
by: Richard Cornford | last post by:
For the last couple of months I have been trying to get the next round of updates to the FAQ underway and been being thwarted by a heavy workload (the project I am working on has to be finished an...
21
by: Michael Bierman | last post by:
Please forgive the simplicy of this question. I have the following code which attempts to determine the color of some text and set other text to match that color. It works fine in Firefox, but does...
1
by: Aravind G via .NET 247 | last post by:
(Type your message here) -------------------------------- From: Aravind G Hello all, I have a peculiar situation. Following is a small xml snippet in use
2
by: Eranga | last post by:
Is there any way that we can serach for a registry key value with a known data. For example if I want to find a registry value with the known data"InternetSearch" how can I do it on C#? for any...
4
by: andreas.w.h.k. :-\) | last post by:
How do I change the address location in the wsdl <wsdl:port name="SearchSoap12" binding="tns:SearchSoap12"> <soap12:address location="http://searchservices/engine/search.asmx" /> </wsdl:port> ...
3
by: Goran Djuranovic | last post by:
Hi All, Does anyone know how to retreive deepest XPath value from XML document by using VB.NET? For example, if I had an XML file like this: <Root> <Customer> <Name>MyName</Name> </Customer>...
2
by: Bilal | last post by:
Hello, I'm stuck on this problem for quite some time and hope somebody would be able to guide me. Basically, I need to populate a large number of "template" XML files which have all...
5
by: yhlove | last post by:
Hi I'm trying to change element in xml file as described below: the xml file: ---------------- <MyProg> <Path>test1</Path> </MyProg>
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.