aletri
Goto Top

Per vbscript xml Knoten an bestehenden Knoten anhängen

Guten Tag
Komme mit unten aufgeführtem Code nicht weiter, da ich nicht weiss wie man das Element "SeasonEntry" and das "ModelEntry" Element anhängt?
Code funktioniert nur wird der " SeasonEntry" an das RootElement angehägt!!

Set xmlDoc = CreateObject("MSXML2.DOMDocument.6.0")  
xmlDoc.async = False
xmlDoc.load("C:\zATi\AutogenDescriptions.xml")  
Set xmlRoot = xmlDoc.documentElement
Set nodeInsert = xmlDoc.selectSingleNode("//Autogen.SeasonalModels")  

Set rootElement=xmlDoc.createElement("ModelEntry")    

Set ModelEntryAttribute=xmlDoc.createAttribute("Version")   
Set ModelEntryAttributeText=xmlDoc.createTextNode("4,0")   
ModelEntryAttribute.appendChild(ModelEntryAttributeText)
rootElement.setAttributeNode(ModelEntryAttribute)

Set ModelEntryAttribute=xmlDoc.createAttribute("id")    
Set ModelEntryAttributeText=xmlDoc.createTextNode("{12345678900987654321}")   
ModelEntryAttribute.appendChild(ModelEntryAttributeText)  
rootElement.setAttributeNode(ModelEntryAttribute) 
 
nodeInsert.appendChild(rootElement)

Set objFieldValue = _
  xmlDoc.createElement("ATiTrees")  
objFieldValue.Text = "veg _trees_set_01"  
rootElement.appendChild objFieldValue

  Set objFieldValue = _
  xmlDoc.createElement("MaxScale")  
objFieldValue.Text = "100.000"  
rootElement.appendChild objFieldValue

Set objFieldValue = _
  xmlDoc.createElement("MinScale")  
objFieldValue.Text = "90.000"  
rootElement.appendChild objFieldValue 


Set objRoot = xmlDoc.documentElement
  
Set objRecord = _
  xmlDoc.createElement("SeasonEntry")  
objRoot.appendChild objRecord

Set objFieldValue = _
  xmlDoc.createElement("ModelGuid")  
objFieldValue.Text = "{12345678900987654321}"  
objRecord.appendChild objFieldValue

xmlDoc.Save"C:\zATi\TestAutogenDescriptions.xml"  
Set xmlDoc = Nothing

Content-Key: 340379

Url: https://administrator.de/contentid/340379

Printed on: April 19, 2024 at 16:04 o'clock

Mitglied: 133417
133417 Jun 12, 2017 updated at 11:53:29 (UTC)
Goto Top
Codezeilen kommentieren trägt auch zu deinem Verständnis besser bei ....

Du musst erst alle Knoten von innen nach Außen an die Objekte hängen, deine Reihenfolge ist einfach falsch. Du hängst ChildObjects nach dem Einhängen in das DOM an das Objekt und das ist dein Fehler.
Set xmlDoc = CreateObject("MSXML2.DOMDocument.6.0")  
xmlDoc.async = False
xmlDoc.load("C:\zATi\AutogenDescriptions.xml")  
Set xmlRoot = xmlDoc.documentElement
Set nodeInsert = xmlDoc.selectSingleNode("//Autogen.SeasonalModels")  

Set rootElement=xmlDoc.createElement("ModelEntry")    

Set ModelEntryAttribute=xmlDoc.createAttribute("Version")   
Set ModelEntryAttributeText=xmlDoc.createTextNode("4,0")   
ModelEntryAttribute.appendChild(ModelEntryAttributeText)
rootElement.setAttributeNode(ModelEntryAttribute)

Set ModelEntryAttribute=xmlDoc.createAttribute("id")    
Set ModelEntryAttributeText=xmlDoc.createTextNode("{12345678900987654321}")   
ModelEntryAttribute.appendChild(ModelEntryAttributeText)  
rootElement.setAttributeNode(ModelEntryAttribute) 
 
Set objFieldValue = _
  xmlDoc.createElement("ATiTrees")  
objFieldValue.Text = "veg _trees_set_01"  
rootElement.appendChild objFieldValue

  Set objFieldValue = _
  xmlDoc.createElement("MaxScale")  
objFieldValue.Text = "100.000"  
rootElement.appendChild objFieldValue

Set objFieldValue = _
  xmlDoc.createElement("MinScale")  
objFieldValue.Text = "90.000"  
rootElement.appendChild objFieldValue 

Set objRecord = xmlDoc.createElement("SeasonEntry")  

Set objFieldValue = _
  xmlDoc.createElement("ModelGuid")  
objFieldValue.Text = "{12345678900987654321}"  
objRecord.appendChild objFieldValue

rootElement.appendChild objRecord
nodeInsert.appendChild rootElement

xmlDoc.Save"C:\zATi\TestAutogenDescriptions.xml"  
Set xmlDoc = Nothing
Gruß