[mapguide-users] XML Parser error for Feature Sources

Kenneth Skovhede, GEOGRAF A/S ks at geograf.dk
Mon Dec 1 07:57:51 EST 2008


I believe the problem is the .Net UTF-8 Encoder prefixes an UTF-8 BOM,
which causes problems in the Xml parser:
http://trac.osgeo.org/mapguide/ticket/233

You can try to create the UTF-8 encoder with:

UTF8Encoding utf8 = new UTF8Encoding(false);


And see if the problem goes away.
Alternatively you can use the MaestroAPI instead of messing with the raw 
Xml:
http://trac.osgeo.org/mapguide/wiki/maestro/MaestroAPI

Regards, Kenneth Skovhede, GEOGRAF A/S



cagray skrev:
> Hi,
>
> I have a web application in .NET c# which allows a user to define their own
> feature sources and set the connection parameters. It is very similar to
> doing the same through map guide's own interface. However no matter I do to
> the xml in the code behind I get the error:
>
> An exception occurred in the XML parser.
>
> this gives me no detail why so is very hard to debug. I have validated the
> xml against the xsd and it validates fine. Example of xml below:
>
> <?xml version="1.0" encoding="utf-8"?>
> <FeatureSource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xsi:noNamespaceSchemaLocation="FeatureSource-1.0.0.xsd">
>   <Provider>OSGeo.SHP</Provider>
>   <Parameter>
>     <Name>DefaultFileLocation</Name>
>     <Value>d:\Data\OLPSample_EDC\Local Plan\Lines_ polygon\economic
> development opportunities.shp</Value>
>   </Parameter>
> </FeatureSource>
>
> My method is to grab the xml from mapguide as:
>
>             XmlDocument xmlDoc = new XmlDocument();
>             xmlDoc.PreserveWhitespace = true;
>
>             string strXml =
> resourceService.GetResourceContent(resourceID).ToString();
>             xmlDoc.LoadXml(strXml);
>
> Then I traverse the xml structure and edit node's InnerText or add nodes as
> appropriate. Once done I do:
>
> 	MgByteSource byteSource = getResourceByteSource(xmlDoc);
> 	MgResourceIdentifier resourceID = new MgResourceIdentifier(whereToString +
> "//" + resourceName + "." + resourceType);
> 	resourceService.SetResource(resourceID, byteSource.GetReader(), null);
>
> where the getResourceByteSource function looks like:
>
> public MgByteSource getResourceByteSource(XmlDocument xmlDoc)
>         {
>             MemoryStream memStream = new MemoryStream();
>             xmlDoc.Save(memStream);
>             Byte[] arrBytes = memStream.ToArray();
>
>             UTF8Encoding utf8 = new UTF8Encoding();
>             byte[] encodedDefinition =
> utf8.GetBytes(xmlDoc.InnerXml.ToString());
>             MgByteSource contentByteSource = new
> MgByteSource(encodedDefinition, encodedDefinition.Length);
>
>             return contentByteSource;
>         }
>
> This works completely find for editing layer definitions but no matter what
> I do with feature source xml it returns this error. I have tried hand coded
> xml strings, adding spaces, removing formatting etc. I even have tried just
> taking a feature resource straight out and trying to put it back without any
> changes and this error still occurs. 
>
> Anyone ever seen this before (and hopefully got round it)?
>
> Thanks
> Colin
>
>
>
>
>   


More information about the mapguide-users mailing list