Edition fichier XML (problème séléction de noeud)
Bonjour,
Je cherche à modifier certaines valeurs dans un fichier XML dont voici un extrait :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| <?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
<settings pass="windowsPE">
<component name="Microsoft-Windows-International-Core-WinPE" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="NonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SystemLocale>fr-FR</SystemLocale>
<UserLocale>fr-FR</UserLocale>
<UILanguage>fr-FR</UILanguage>
<UILanguageFallback>fr-FR</UILanguageFallback>
<InputLocale>100c:0000100c</InputLocale>
<SetupUILanguage>
<UILanguage>fr-FR</UILanguage>
</SetupUILanguage>
</component>
<component name="Microsoft-Windows-Setup" processorArchitecture="amd64" 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>
<ProductKey>
<WillShowUI>OnError</WillShowUI>
<Key>D4F6K-QK3RD-TMVMJ-BBMRX-3MBMV</Key>
</ProductKey>
</UserData>
<Display>
<ColorDepth>32</ColorDepth>
<HorizontalResolution>1024</HorizontalResolution>
<VerticalResolution>768</VerticalResolution>
</Display>
<ImageInstall>
<OSImage>
<InstallFrom>
<MetaData wcm:action="add">
<Key>/IMAGE/INDEX</Key>
<Value>1</Value>
</MetaData>
</InstallFrom>
</OSImage>
</ImageInstall>
</component>
</settings>
</unattend> |
Admettons que je veuille modifier la valeur de <SystemLocale> en "en-EN" voici mon code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
' Load the XmlDocument.
Dim xd As New XmlDocument()
xd.Load(OpenFileDialog1.FileName)
' Find the node
Dim nod As XmlNode = xd.SelectSingleNode("/unattend/settings[@pass='windowsPE']/component[@name='Microsoft-Windows-International-Core-WinPE']")
Try
' change the InnerText of 1st childnode.
nod.ChildNodes(0).InnerText = "en-EN"
Catch ex As Exception
MsgBox(ex.Message)
End Try
' Save the Xml.
xd.Save(System.IO.Path.GetDirectoryName(OpenFileDialog1.FileName) & "/test.xml")
End Sub |
J'obtiens l'erreur suivante :
Citation:
La référence d'objet n'est pas définie à une instance d'un objet.
C'est sûrement tout bête, mais je ne trouve pas mon erreur... :? Je précise que c'est pour moi la première fois que je m'attaque à l’édition d'un fichier XML. J'ai peut-être loupé quelque chose?
Si quelqu'un à une idée ou une suggestion pour faire la chose différemment?
D'avance merci beaucoup pour votre aide! :D