Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Duplicate XML element when generating for musicxml #315

Closed
WilliamQiufeng opened this issue Mar 26, 2022 · 2 comments
Closed

Duplicate XML element when generating for musicxml #315

WilliamQiufeng opened this issue Mar 26, 2022 · 2 comments

Comments

@WilliamQiufeng
Copy link

This is part of musicxml.xsd from here:

	<xs:complexType name="part-list">
		<xs:annotation>
			<xs:documentation>The part-list identifies the different musical parts in this document. Each part has an ID that is used later within the musical data. Since parts may be encoded separately and combined later, identification elements are present at both the score and score-part levels. There must be at least one score-part, combined as desired with part-group elements that indicate braces and brackets. Parts are ordered from top to bottom in a score based on the order in which they appear in the part-list.</xs:documentation>
		</xs:annotation>
		<xs:sequence>
			<xs:group ref="part-group" minOccurs="0" maxOccurs="unbounded"/>
			<xs:group ref="score-part"/>
			<xs:choice minOccurs="0" maxOccurs="unbounded">
				<xs:group ref="part-group"/>
				<xs:group ref="score-part"/>
			</xs:choice>
		</xs:sequence>
	</xs:complexType>

I used command arguments-o out/ --collectionSettersMode=Public --nc --nu -n "=MusicXml" <pathto>/musicxml.xsd.
This generated collections Part_Group and Part_Group_2, which throws this when trying to deserialize:

...
---> System.InvalidOperationException: There was an error reflecting property 'Part_Group_2'.
 ---> System.InvalidOperationException: The XML element 'part-group' from namespace '' is already present in the current scope. Use XML attributes to specify another XML name or namespace for the element.
   at System.Xml.Serialization.XmlReflectionImporter.AddUniqueAccessor(INameScope scope, Accessor accessor)
   at System.Xml.Serialization.XmlReflectionImporter.AddUniqueAccessor(MemberMapping member, INameScope elements, INameScope attributes, Boolean isSequence)
   at System.Xml.Serialization.XmlReflectionImporter.InitializeStructMembers(StructMapping mapping, StructModel model, Boolean openModel, String typeName, RecursionLimiter limiter)
   --- End of inner exception stack trace ---
...

using

var serializer = new XmlSerializer(typeof(Score_Partwise));
var xml = serializer.Deserialize(new FileStream(path, FileMode.Open)) as Score_Partwise;

I'm rather new to this so I have no idea how to resolve this problem.

@mganss
Copy link
Owner

mganss commented Mar 31, 2022

I have a feeling this occurs because of the way choice elements are handled. I won't be able to investigate in more detail until next week, though.

@mganss
Copy link
Owner

mganss commented Apr 4, 2022

This does indeed occur because of the way choice elements are supported. See here: https://github.com/mganss/XmlSchemaClassGenerator#choice-elements
I've created a workaround for these cases where multiple properties would be generated for the same element. This is in 2.0.662. Feel free to reopen or create a new issue if you still encounter problems.

@mganss mganss closed this as completed Apr 4, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants