[mapguide-users] XML Parser error for Feature Sources

cagray colin.gray at 1spatial.com
Mon Dec 1 06:30:50 EST 2008


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




-- 
View this message in context: http://www.nabble.com/XML-Parser-error-for-Feature-Sources-tp20770245p20770245.html
Sent from the MapGuide Users mailing list archive at Nabble.com.



More information about the mapguide-users mailing list