Fixed parsing of coalesced objects if the XML starts with an XML Declaration ("<xml ...>")

Resolves http://opensimulator.org/mantis/view.php?id=6944
0.8.0.3
Oren Hurvitz 2013-11-18 13:14:49 +02:00
parent 1a32b35279
commit 1769e93c42
1 changed files with 47 additions and 46 deletions

View File

@ -125,15 +125,16 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
// m_log.DebugFormat("[COALESCED SCENE OBJECTS SERIALIZER]: TryFromXml() deserializing {0}", xml); // m_log.DebugFormat("[COALESCED SCENE OBJECTS SERIALIZER]: TryFromXml() deserializing {0}", xml);
coa = null; coa = null;
int i = 0;
try
{
// Quickly check if this is a coalesced object, without fully parsing the XML
using (StringReader sr = new StringReader(xml)) using (StringReader sr = new StringReader(xml))
{ {
using (XmlTextReader reader = new XmlTextReader(sr)) using (XmlTextReader reader = new XmlTextReader(sr))
{ {
try reader.MoveToContent(); // skip possible xml declaration
{
reader.Read();
if (reader.Name != "CoalescedObject") if (reader.Name != "CoalescedObject")
{ {
// m_log.DebugFormat( // m_log.DebugFormat(
@ -142,18 +143,23 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
return false; return false;
} }
}
}
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
XmlElement e = (XmlElement)doc.SelectSingleNode("/CoalescedObject");
if (e == null)
return false;
coa = new CoalescedSceneObjects(UUID.Zero); coa = new CoalescedSceneObjects(UUID.Zero);
reader.Read();
while (reader.NodeType != XmlNodeType.EndElement && reader.Name != "CoalescedObject") XmlNodeList groups = e.SelectNodes("SceneObjectGroup");
int i = 0;
foreach (XmlNode n in groups)
{ {
if (reader.Name == "SceneObjectGroup") SceneObjectGroup so = SceneObjectSerializer.FromOriginalXmlFormat(n.OuterXml);
{
string soXml = reader.ReadOuterXml();
SceneObjectGroup so = SceneObjectSerializer.FromOriginalXmlFormat(soXml);
if (so != null) if (so != null)
{ {
coa.Add(so); coa.Add(so);
@ -170,19 +176,14 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
i++; i++;
} }
} }
reader.ReadEndElement(); // CoalescedObject
}
catch (Exception e) catch (Exception e)
{ {
m_log.ErrorFormat( m_log.Error(string.Format(
"[COALESCED SCENE OBJECTS SERIALIZER]: Deserialization of xml failed with {0} {1}", "[COALESCED SCENE OBJECTS SERIALIZER]: Deserialization of xml failed with {0} ",
e.Message, e.StackTrace); e.Message), e);
return false; return false;
} }
}
}
return true; return true;
} }