XmlSchemaInference to convert XML to XSD



I have XML similar to this:



<project>
<task id="1">
<description>something to do</description>
<assignedTo>name1</assignedTo>
<assignedTo>name2</assignedTo>
<depends>3</depends>
<depends>4</depends>
<task id="2">
<description>child of task 1</description>
<timeSpent>3.2</timeSpent>
</task>
</task>
<task id="3">
<description>do this too</description>
</task>
<task id="4">
<description>and do this</description>
</task>
</project>


Summary:



  • Task 1 is dependent upon tasks 3 and 4 to be completed.

  • Task 1 has been assigned to two collaborators for processing.

  • Task 2 is a sub-task of task 1.

  • Tasks 3 and 4 have no dependencies and no one assigned.

  • 3.2 hours have been spent on task 2, no time has been spent on the other tasks.

  • This is a manually contrived XML document for this example, the real one is more complex.


The xsd.exe utility has no issue creating XSD which recognizes 0 or more assignedTo elements, but it chokes on multiple 'depends' elements with : "A column named 'DEPENDS' already belongs to this DataTable: cannot set a nested table name to the same name." That's just too weird. I don't want to struggle to figure out why one node is OK but the other isn't, but I'd appreciate if someone can offer a suggestion. To avoid solving that and running into another limitation I've opted to write my own XML to XSD converter in C# with XmlSchemaInference.


What I've found with this and other such tools is that it doesn't understand the concept of recursive/nested nodes. As seen above, any task can contain 0 or more other tasks, and the schema for all of these is the same. I'm thinking that because task 2 has a node that's not found elsewhere that the inference thinks it's different. The result is a task with a complex node that includes another task which is also fully defined as a complex node. I'd rather that it infer that the one and only Task element can have 0 or more Task elements, and that all Task elements can have 0 or 1 timeSpent nodes.


Rather than cleansing the XML, I'd like to make the tools work a little smarter. (Though tweaking the XML to get the desired effects is a valid solution in this case!)


Question 1: So without tweaking the XML, I'd like to know if we can generate a single Task element which includes the parameters from all aggregated/nested examples.


Question 2: The next step from here is to generate a dataset from the XSD. I have schema with this line:



<xs:schema id="NewDataSet" xmlns=""
xmlns:xs="http://ift.tt/tphNwY"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">


Can we generate the msdata schema with XmlSchemaInference? That results in a node followed by a ref to all the other inferred elements:



<xs:element name="NewDataSet" msdata:IsDataSet="true"


Thanks!


No comments:

Post a Comment