XSD specifications for XML files can share common elements. If I have several XML files that share a common element, is there a way to extract the common element without repeating the code for each XML file type?
For example: There are a number of XML files defined via XSD, with a common description element, but different content structures elsewhere. The description has subelements with things like author, date, etc. When I create a type provider for each of the XML files, the types are different, so if I only want to extract the description section out of each, the code has to be copy pasted for each of the types.
XML file 1:
<root>
<description >
<author> Me </author>
</description>
<element > Data </element>
<otherelement> Data </otherelement>
</root>
XML file 2:
<root2>
<description >
<author> Me </author>
</description>
<elem > Data </elem>
<diffelem> Data </diffelem >
</root2>
Would require the code to be something like:
type File1 = XmlProvider<""".\file1.xml""">
type File2 = XmlProvider<""".\file2.xml""">
let descript1 =
File1.GetSample().description.author
let descript2 =
File2.GetSample().description.author //duplicated code
Simple in this case, but gets more involved with a longer description and more xml file types.
Is there a way around this? Can a type provider be created for a subset of an XML file and only extract those parts so the code can be more reusable?