Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have the following xml file :

XML
<MACHINE>
  <NAME />
  <RECIPE>
    <NAME>
      <PARAMETER>
        <NAME>Tempete</NAME>
        <ACCESS_LEVEL />
        <HISTO_DAY_MAX />
        <HISTORY>
          <UPDATE>
            <VALUE>1</VALUE>
            <DATE>20,04,2023 01:53:28</DATE>
          </UPDATE>
          <UPDATE>
            <VALUE>1</VALUE>
            <DATE>20,04,2023 01:53:28</DATE>
          </UPDATE>
        </HISTORY>
      </PARAMETER>
      <PARAMETER>
        <NAME>Temps de fin de cycle</NAME>
        <ACCESS_LEVEL />
        <HISTO_DAY_MAX />
        <HISTORY />
      </PARAMETER>
      <PARAMETER>
        <NAME>Vitesse pendant la correction</NAME>
        <ACCESS_LEVEL />
        <HISTO_DAY_MAX />
        <HISTORY />
      </PARAMETER>
    </NAME>
  </RECIPE>
</MACHINE>


I want to check if a parameter name already exists and if so add in the History node a new element. So far I've managed to find out if the parameter name already exists with a for loop but I can't add a new element in the HITSORY node

What I have tried:

VB
nodeSearch=doc.SelectNodes("/MACHINE/RECIPE/NAME/PARAMETER/NAME");

	for each nodd in nodeSearch
		if nodd.InnerText.ToString()== Designation.ToString() then
			testParam = true;
			nameNode = nodd;
		endif;

...


	else
		Update = doc.CreateElement("UPDATE");
		node = nameNode.ParentNode.SelectSingleNode("/HISTORY");
		Value = doc.CreateElement("VALUE");
		Date = doc.CreateElement("DATE");

	next;
Posted
Comments
Member 15627495 21-Apr-23 3:14am    
have you try : ?
doc.createelement(name, value)


or for multiple contents :
with Xelement : // by multiple Elements to add with different depth :
dim XELEM as Xelement = new Xelement(name_1 , new xelement("name_2", value_2) , value_1 )
node.add(XELEM)
Leo Bois 21-Apr-23 3:37am    
Thx I'll try it
Richard Deeming 21-Apr-23 3:28am    
You've tagged this as "VB", but the code you've tried is nothing like any version of VB I've ever seen. Either you've pasted the wrong code, or you've tagged this question with the wrong language.
Leo Bois 21-Apr-23 3:37am    
It's VB .net framework
Richard Deeming 21-Apr-23 3:38am    
The code you've posted is most certainly NOT VB.NET; have you copied code from somewhere else without checking the language it was written in?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900