DiomedesDominguez / kml-library

Automatically exported from code.google.com/p/kml-library
0 stars 0 forks source link

Exception parsing KML 2.2 #1

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Save KML from Google Earth v. 4.2.0205.5730
2. Attempt to create KMLRoot object via method KMLRoot.Load([path]);

What is the expected output? What do you see instead?
Causes exception XML Deserialiser.

What version of the product are you using? On what operating system?
r5 on WinXP SP2, VS2005

Please provide any additional information below.
System.InvalidOperationException was unhandled
  Message="There is an error in XML document (2, 2)."
  Source="System.Xml"
  StackTrace:
       at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader
xmlReader, String encodingStyle, XmlDeserializationEvents events)
       at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader
xmlReader, String encodingStyle)
       at System.Xml.Serialization.XmlSerializer.Deserialize(Stream stream)
       at Core.Xml.XMLSerializeManager.DeserializeObjectFromFile(String
file_path, Type pType) in
C:\Resources\kml-library\Core\Xml\XmlSerializer.cs:line 140
       at Core.Xml.XmlSerializer`1.DeserializeObjectFromFile(String
file_path) in C:\Resources\kml-library\Core\Xml\XmlSerializer.cs:line 206
       at KMLib.KMLRoot.Load(String path) in
C:\Resources\kml-library\KMLib\kml.cs:line 20
       at KmlTestbed.TestFrm.button2_Click(Object sender, EventArgs e) in
C:\Resources\kml-library\KmlTestbed\TestFrm.cs:line 89
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNat
iveMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
       at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
       at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason,
ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at KmlTestbed.Program.Main() in
C:\Resources\kml-library\KmlTestbed\Program.cs:line 16
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()

Original issue reported on code.google.com by ahosie@gmail.com on 14 Apr 2008 at 7:15

GoogleCodeExporter commented 9 years ago
This error is due to the XmlSerializer encountering the unexpected KML header 
element (as it is expecting straight XML elements). I am trying to work out how 
to 
use XmlSerializer for serialising/deserialising XML and am having this problem.
Cheers,
Katie

Original comment by katie.an...@gmail.com on 3 Jun 2008 at 10:56

GoogleCodeExporter commented 9 years ago
The Serializer has been developed to Schema version 2.1 and google maps is now
outputting version 2.2 and the header of .... 2.2 is not recognised?

Original comment by sirjohnf...@gmail.com on 24 Jun 2008 at 12:25

GoogleCodeExporter commented 9 years ago
in kml.cs change the class declaration to look like this:

 [XmlRoot(ElementName = "kml", Namespace = "http://www.opengis.net/kml/2.2")]
    //--if you add the namespace, then all children get a blank namespace attrib...
    // [XmlRoot(ElementName = "kml")]
    public class KMLRoot
    {

That got me around this issue, the other option is to strip the attributes out 
of the 
KML file you are deserializing altogether before loading it. 

ie change

<kml xmlns="http://www.opengis.net/kml/2.2" 
xmlns:gx="http://www.google.com/kml/ext/2.2" 
xmlns:kml="http://www.opengis.net/kml/2.2" 
xmlns:atom="http://www.w3.org/2005/Atom">

to

<kml>

Original comment by deathpat...@gmail.com on 8 Jul 2009 at 6:05

GoogleCodeExporter commented 9 years ago
Add the namespace declaration to the xmlroot attribute as mentioned by 
deathpatrolband and also around ln 76 of XmlSerializer.cs change the namespace 
manager declaration like so:

   XmlSerializerNamespaces xmlns = new XmlSerializerNamespaces();
   xmlns.Add("", "http://www.opengis.net/kml/2.2");

That will ditch the xsi and xsd namespaces.

Original comment by tinsoldi...@gmail.com on 20 Aug 2010 at 1:11

GoogleCodeExporter commented 9 years ago
I am trying this but cannot seem to get any results from trying the 
suggestions, was wondering if this worked for everyone that tried it?

Original comment by millsybo...@googlemail.com on 25 Sep 2012 at 8:53