0

My questions is semi-related to: Is it possible to get the type of an XML node as it was defined in XSD?

...but this question was not answered and it targets python, whereas I am interested in a C#.Net solution. My question is: how can you get a type, defined in an XSD, expressed as a type in .Net?

Background: If it helps, my goal is to use xpath to locate a section within an XML document, find that section's corresponding type in the supporting XSD, and finally use the type to then de-serialize that section into a .Net object.

Generally, I can de-serialize the xml if I know the type at compile-time, but at run-time, the type must be inferred using an xpath query. I think this could be achieved using reflection, but I am wondering also if there isn't something already present in the .Net Framework I could leverage.

Stated another way, I'd like to do the opposite of this:

private void ExtractXsdFromType(Type type, FileInfo xsd)
{
    XmlReflectionImporter importer = new XmlReflectionImporter();
    XmlTypeMapping mapping = importer.ImportTypeMapping(type);
}

... where rather than passing in a type to get the mapping, I'd be passing in a string to get the type. I hope that is clear enough, but if not please request clarification and I will provide more details.

Thanks for your experience!

Community
  • 1
  • 1
ISZ
  • 1,027
  • 2
  • 14
  • 29

1 Answers1

0

rather than passing in a type to get the mapping, I'd be passing in a string to get the type.

Given a Qualified Assembly Name, you can retrieve the corresponding Type object using Type.GetType(). For example, Type.GetType("ReflectionTest.TestClass") returns the type for the class TestClass defined in the ReflectionTest namespace.

user845279
  • 2,794
  • 1
  • 20
  • 38