Changing XML Values

ayozzhero

Well-known member
Joined
Apr 6, 2005
Messages
186
Location
Malaysia
Programming Experience
1-3
Let's say this is the XML file:

VB.NET:
<?xml version="[color=DimGray]1.0[/color]" encoding="[color=DimGray]UTF-8[/color]"?>
 <SoftwareSetting>
	<Layout>
		<DefaultFont>[color=RoyalBlue]Arial[/color]<DefaulfFont>
		<DefaultFontSize>[color=RoyalBlue]12[/color]<DefaultFontSize>
	</Layout>
	<Printer>
		<Brand Name="[color=DimGray]Canon[/color]">
			<DefaultOrientation>[color=RoyalBlue]0[/color]<DefaultOrientation>
		</Brand>
		<Brand Name="[color=DimGray]Epson[/color]">
			<DefaultOrientation>[color=RoyalBlue]0[/color]<DefaultOrientation>
		</Brand>
	</Printer>
</SoftwareSetting>

I know how to read XML file. But how to change the <DefaultFont> value, for example from Arial to Times New Roman? And howto change the <Brand Name="Epson"> to <Brand Name="HP">?

I have another problem with XML, but I will do it in another thread later.

Thank you for helping.
 
oh simple you have to load it in XMLDocument and then use XPath Query to retreive the element "DefaultFont" (you can also reach the element with iterating sequentailly however it all depends upon ur choice i ll prefer XPath)
like
Dim doc as new XmlDocument()
doc.Load("filename") ' or you can use doc.LoadXml("all the xml")
Dim font as XmlNode
font = doc.SelectSingleNode("//DefaultFont/text()")
font.value = "new font name"


thats it similarly you can access other elements as well
 
Back
Top