How can I serialize an IFeatureClass object to XML?
There are some resources for using IXMLSerializer on other ArcObjects, but that won’t work for IFeatureClass because it doesn’t implement ISerializable.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’ve actual found my own answer to this question. I’m posting this question and answer here for the benefit of others and for feedback/critique on my approach.
IFeatureClass cannot be serialized directly, but IRecordSet2 can be. So the first step is implementing a method to convert IFeatureClass to IRecordSet2:
Then it’s easy to use IXMLSerializer to get XML:
However, when you convert to IRecordSet2, you lose the feature class name, so when writing to a file, I add an element to the XML to hold the feature class name:
Now, just reverse the process to read the XML into a feature class. Remember that an element was added to store the feature class name:
Simple de-serialization using IXMLSerializer to get a IRecordSet2:
This was the tricky part. I’m open to suggestions on how to improve this … covert the IRecordSet2 object into an IFeatureClass:
Finally, a utility method for deleting an existing dataset. This was copy/pasted from somewhere, but I can’t remember the source.