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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add XML Node with VBS

Status
Not open for further replies.

BernLap

Programmer
Jun 18, 2021
1
CA
Hi everyone,

I'm trying to add XML Node in an XML file with VBS but it don't work (nothing is added).

Can anyone help me ?

XML:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!--Phone Account Settings-->
<Accounts>
	<Profiles>
		<Profile>
			<IsActive>True</IsActive>
			<AuthByPassword>True</AuthByPassword>
			<AuthUser>iWz6iobPfr</AuthUser>
			<Codecs>PCMU/8000/1,True;PCMA/8000/1,True;G722/16000/1,True;G729/8000/1,True;opus/48000/2,True;GSM/8000/1,False;speex/8000/1,False;iLBC/8000/1,False</Codecs>
			<MaxRegistrationTime>120</MaxRegistrationTime>
			<SIPTransport>0</SIPTransport>
			<StunAttempts>2</StunAttempts>
			<AuthPassword></AuthPassword>
			<UseTunnel>True</UseTunnel>
			<PBXPort>5060</PBXPort>
			<SwitchboardMode>UserMode</SwitchboardMode>
			<ShowUnregisteredExtensions>True</ShowUnregisteredExtensions>
			<PresenceLayoutOrientation>Vertical</PresenceLayoutOrientation>
			<PresenceViewMode>Grouped</PresenceViewMode>
			<ActiveCallsFilter>115</ActiveCallsFilter>
			<HiddenGroups>2</HiddenGroups>
			<HiddenWallboardQueues></HiddenWallboardQueues>
			<WallboardCustomMessage1>3CX Wallboard</WallboardCustomMessage1>
			<WallboardCustomMessage2></WallboardCustomMessage2>
		</Profile>
	</Profiles>
	<General>
		<EchoCancellation>True</EchoCancellation>
		<VAD>False</VAD>
		<MicGain>4</MicGain>
		<IsBusyLampFieldExpanded>False</IsBusyLampFieldExpanded>
		<SwitchboardWindowLeft>1433</SwitchboardWindowLeft>
		<SwitchboardWindowTop>22</SwitchboardWindowTop>
		<SwitchboardWindowWidth>312</SwitchboardWindowWidth>
		<SwitchboardWindowHeight>800</SwitchboardWindowHeight>
		<IsSwitchboardWindowMaximized>False</IsSwitchboardWindowMaximized>
		<DefaultDragAndDropTransferType>Blind</DefaultDragAndDropTransferType>
		<ActiveCallsCallerColumnWidth>150</ActiveCallsCallerColumnWidth>
		<ActiveCallsCalleeColumnWidth>150</ActiveCallsCalleeColumnWidth>
		<ActiveCallsDurationColumnWidth>60</ActiveCallsDurationColumnWidth>
		<SwitchboardLayoutTop>428</SwitchboardLayoutTop>
		<SwitchboardLayoutBottom>1000</SwitchboardLayoutBottom>
		<SwitchboardLayoutLeft>1</SwitchboardLayoutLeft>
		<SwitchboardLayoutRight>1</SwitchboardLayoutRight>
		<CustomImagePath>C:\ProgramData\3CXPhone for Windows\PhoneApp\HeaderImage.jpeg</CustomImagePath>
	</General>
</Accounts>


I wanted to add a node in the General section (at the end like after CustomImagePath). Here's my code.

Code:
Set xmlDoc=CreateObject("Microsoft.XMLDOM")
xmlDoc.load XMLFILE

'Locate the node 
Set nNode2 = xmlDoc.selectsinglenode(XMLNODE)

'Validate if existing
If nNode2 Is Nothing Then
	newEle = xmlDoc.createNode("IsCustomImageSet")
	newText=xmlDoc.createTextNode("True")
	newEle.appendChild(newText)
	
	x = xmlDoc.getElementsByTagName("General")[0]
	x.appendChild(newEle)
	
	'set root = xmlDoc.documentElement("General")
	'set new_book = xmlDoc.createNode(1, "IsCustomImageSet", "")
	'set book_text = xmlDoc.createNode(3, "", "")
	'book_text.text = "True"
	'new_book.appendChild(book_text)
	'root.insertBefore new_book, root.childNodes.Item(0)
	
End if

'Save the setting
strResult = xmldoc.save(XMLFILE)

Thanks for you help! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top