Rank: Newbie
Joined: 8/5/2009 Posts: 1 Location: New Jersey
|
Does anyone have any C# code example for accessing xsd metadata?
|
Rank: Advanced Member
Joined: 5/16/2009 Posts: 82
|
Hi Jim,
You can generate C# code based on your xsd with XMLSpy. Then you have easy access to the schema metadata, as explained in this page:
https://www.altova.com/manual/XMLSpy/spyenterprise/using_the_generated_c_library2.htm
So if you want, for example, retrieve the MaxOccur and MinOccur values, then you can do this (based on the second example in the link above):
protected static void Example() { Library.Library2 doc = Library.Library2.LoadFromFile("Library.xml"); Library.LibraryType root = doc.Library3.First; Library.BookType book = root.Book.First; System.Console.WriteLine(root.Book.Info.MinOccurs); System.Console.WriteLine(root.Book.Info.MaxOccurs); }
Cheers
|