From 6701fc2ffa426912fe7a4b208eaeec6d2defce15 Mon Sep 17 00:00:00 2001 From: Melanie Date: Tue, 29 Jun 2010 21:50:52 +0100 Subject: Fix the XML serializationt to provide an empty script state element if the script hasn't yet saved state, or can't save state because of a loop --- OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 32 ++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index 61a2088..4715690 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -1274,9 +1274,23 @@ namespace OpenSim.Region.ScriptEngine.XEngine string xml = instance.GetXMLState(); XmlDocument sdoc = new XmlDocument(); - sdoc.LoadXml(xml); - XmlNodeList rootL = sdoc.GetElementsByTagName("ScriptState"); - XmlNode rootNode = rootL[0]; + bool loadedState = true; + try + { + sdoc.LoadXml(xml); + } + catch (System.Xml.XmlException e) + { + loadedState = false; + } + + XmlNodeList rootL = null; + XmlNode rootNode = null; + if (loadedState) + { + rootL = sdoc.GetElementsByTagName("ScriptState"); + rootNode = rootL[0]; + } // Create XmlDocument doc = new XmlDocument(); @@ -1292,8 +1306,18 @@ namespace OpenSim.Region.ScriptEngine.XEngine stateData.Attributes.Append(engineName); doc.AppendChild(stateData); + XmlNode xmlstate = null; + // Add ... - XmlNode xmlstate = doc.ImportNode(rootNode, true); + if (loadedState) + { + xmlstate = doc.ImportNode(rootNode, true); + } + else + { + xmlstate = doc.CreateElement("", "ScriptState", ""); + } + stateData.AppendChild(xmlstate); string assemName = instance.GetAssemblyName(); -- cgit v1.1