Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating XML value 1

Status
Not open for further replies.

HVtech

IS-IT--Management
Jul 1, 2010
71
NL
Hi,
I'm trying to update a value which is stored in a xml file.
Preferable through a popup where the input (new value) is typed in.
Any help is much aprreciated!
This is what I have found, but not working..
Code:
'Define what our new value will be and place it into a variable
sValue = "Testvalue"

'Get path of script, (scriptfullname), then replace the scriptname with nothing  bring us only the path and place it into strScriptPath
strScriptPath = replace(wscript.scriptfullname,wscript.scriptname,"")

'Create XMLDoc object
Set xmlDoc = CreateObject("Microsoft.XMLDOM")

'load up the XML file and place it into xmldoc
xmlDoc.load strScriptPath & "config.xml"

'Select the node we want to edit
'The text IS case sensitive
Set sInboxFolder = xmlDoc.selectsinglenode ("registration")

'Show the current value in FaxInBox
msgbox sInboxFolder.text

'Set the text node with the new value
sInboxFolder.text = sValue

'Save the xml document with the new settings.
iResult = xmldoc.save(strScriptPath & "config.xml")

'You can use the iResult as a way to determine if the file gets saved correctly or not (‘0=yes’, ‘1=no’)
 
><unattend xmlns="urn:schemas-microsoft-com:unattend">
Change it to this as a stop-gap measure, pending your checking of your proprietary namespace.
[tt]<unattend xmlns="urn:schemas-microsoft-com:unattend" [red]xmlns:wcm="urn:wcm-unidentified[/red]">[/tt]
 
The same error: you mean objXMLDoc.xml empty?
 
I use exact vbs and the modified xml and get the desired result.
 
Weird...
Can you post the modified xml?
 
>Can you post the modified xml?
Exactly as I said in my post of "2 Jul 10 9:44". If you have no idea what a well-formed xml document is, it is fair enough. (A well-formed document means not only a tag has to be closed and nesting rule, it means more.) If you still get problem, you tell the forum but not without due diligence.
 
but not without due diligence.
English is not my native language, therefor I don't understand what you mean here.. sorry.
And no, I don't know what a well formatted xml file is...
Just found that WDS is using it for deployment settings, and I'd like to edit it with popups where I can fill in the desired fields.

 
That is just a bit neutral way to ask for a "reasonably effort" on your part, if you can swollow it! How about just go ahead and test it. This thread goes way beyond my quota granted to each question.
 
I am testing it, aint I?
Then I gave you the results (errors).
What am I doing wrong??
 
This is the complete listing of the test file (which is your posting of 2 Jul 10 9:30 with my change of 2 Jul 10 9:44.
[tt]
<?xml version="1.0" ?>
<unattend xmlns="urn:schemas-microsoft-com:unattend" xmlns:wcm="uri:wcm-unidentified">
<settings pass="windowsPE">
<component name="Microsoft-Windows-Setup" publicKeyToken="31bf3856ad364e35"
language="neutral" versionScope="nonSxS" processorArchitecture="x86">
<WindowsDeploymentServices>
<Login>
<WillShowUI>OnError</WillShowUI>
<Credentials>
<Username>******</Username>
<Domain>*******</Domain>
<Password>*******</Password>
</Credentials>
</Login>
<ImageSelection>
<WillShowUI>OnError</WillShowUI>
<InstallImage>
<ImageName>HP-D530SFF_03</ImageName>
<ImageGroup>InstallGroup</ImageGroup>
<Filename>HPD530-03.wim</Filename>
</InstallImage>
<InstallTo>
<DiskID>0</DiskID>
<PartitionID>1</PartitionID>
</InstallTo>
</ImageSelection>
</WindowsDeploymentServices>
<DiskConfiguration>
<Disk wcm:action="add">
<CreatePartitions>
<CreatePartition wcm:action="add">
<Order>1</Order>
<Size>27200</Size>
<Type>Primary</Type>
</CreatePartition>
<CreatePartition wcm:action="add">
<Order>2</Order>
<Type>Extended</Type>
<Extend>true</Extend>
</CreatePartition>
<CreatePartition wcm:action="add">
<Order>3</Order>
<Type>Logical</Type>
<Extend>true</Extend>
</CreatePartition>
</CreatePartitions>
<ModifyPartitions>
<ModifyPartition wcm:action="add">
<Active>true</Active>
<Extend>false</Extend>
<Format>NTFS</Format>
<Label>WinXP</Label>
<Letter>C</Letter>
<Order>1</Order>
<PartitionID>1</PartitionID>
</ModifyPartition>
<ModifyPartition wcm:action="add">
<Active>false</Active>
<Extend>false</Extend>
<Format>NTFS</Format>
<Label>Rommelen</Label>
<Letter>D</Letter>
<Order>2</Order>
<PartitionID>2</PartitionID>
</ModifyPartition>
</ModifyPartitions>
<WillWipeDisk>true</WillWipeDisk>
<DiskID>0</DiskID>
</Disk>
<WillShowUI>OnError</WillShowUI>
</DiskConfiguration>
</component>
<component name="Microsoft-Windows-International-Core-WinPE" publicKeyToken="31bf3856ad364e35"
language="neutral" versionScope="nonSxS" processorArchitecture="x86">
<SetupUILanguage>
<WillShowUI>OnError</WillShowUI>
<UILanguage>en-US</UILanguage>
</SetupUILanguage>
<UILanguage>nl-NL</UILanguage>
</component>
</settings>
</unattend>
[/tt]
ps: the username, domain and password are tested as such. If you use your real data, there can have a small chance to make it ill-formed again. The chance is small except for the password. Make the password starred (*). If you can succeed in testing it, I will give you a method to deal with the password.
 
And your vbs script is same as this?
Code:
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load("Unattendedx86.xml")
wscript.echo objXMLDoc.xml

Set ElemList = objXMLDoc.getElementsByTagName("ImageName")  
plot = ElemList.item(0).Text
WScript.Echo plot

strInput = UserInput( "Nieuwe image naam:" )
WScript.Echo "Nieuwe imagenaam in XML: " & strInput

ElemList.item(0).text=strInput

'Tweede variable
Set ElemList = objXMLDoc.getElementsByTagName("Filename")
plot2 = ElemList.item(0).Text
ElemList.item(0).text=strInput & ".wim"

objXMLDoc.save("Unattendedx86.xml")

Function UserInput( myPrompt )
' This function prompts the user for some input.
' When the script runs in CSCRIPT.EXE, StdIn is used,
' otherwise the VBScript InputBox( ) function is used.
' myPrompt is the the text used to prompt the user for input.
' The function returns the input typed either on StdIn or in InputBox( ).
' Written by Rob van der Woude
' [URL unfurl="true"]http://www.robvanderwoude.com[/URL]
    ' Check if the script runs in CSCRIPT.EXE
    If UCase( Right( WScript.FullName, 12 ) ) = "\CSCRIPT.EXE" Then
        ' If so, use StdIn and StdOut
        WScript.StdOut.Write myPrompt & " "
        UserInput = WScript.StdIn.ReadLine
    Else
        ' If not, use InputBox( )
        UserInput = InputBox( myPrompt )
    End If
End Function

Cause I'm getting same error again, no file loaded (no output on wscript.echo objXMLDoc.xml
and error on line 7:
Object required: 'Elemlist.Item(....)

Again, I really appreciate your help !
code: 800A01A8
 
vbs exactly the same, running with wscript.exe host.
Have you starred username, domain and password?
 
Username domain and pw are not yet an issue, first I want to edit the fields and save the xml.
Then I can test whether the xml file actually works with the changes made (xmlns:wcm="uri:wcm-unidentified)

The username domain and password are just starred because I don't want them public.In the real file, those are just written out. File is on the server so no worries about that.

How is it possible that the script runs when you test it and me getting errors? So can actually fill in whatever you like in the popup input boxes and that is written in the file?
What can I do to get rid of the error?
 
>...first I want to edit the fields and save the xml.
Then I can test whether the xml file actually works with the changes made (xmlns:wcm="uri:wcm-unidentified)


Edit the first line FIRST. That's xml non-negotiable. That is the source of error. That is the point I make all along! Do I have to repeat hundred times?
 
I did change the first line hte minute you told me, to doublecheck I asked you to post the xml you have and it's exactly the same as mine.
Still, I get the same error.
That's why I posted the vbs, to double check for differences.
There are none you say..
 
Sorry, I really am exhausted.
Use a text editor, load the xml file, save it in a ascii text file. And do the test again.
 
Oke working now..
Thank you so much for your patience and time.
Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top