Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any way to check if a XmlSchemaParticle is an EmptyParticle?

Tags:

c#

xml

xsd

I'm struggling with something here, is there a proper way to check whether a XmlSchemaParticle is an EmptyParticle or not?

XmlSchemaParticle.EmptyParticle seems to be a private inner class of XmlSchemaParticle.

What I'm doing right now is particle.GetType().Name == "EmptyParticle" and I find it rather ugly.

Any other option?

like image 512
Bertrand Marron Avatar asked Mar 15 '11 16:03

Bertrand Marron


3 Answers

I ran into same problem today. I was able to get around it by checking XmlSchemaComplexType.ContentType property:

public bool HasEmptyParticle(XmlSchemaComplexType type)
{
    return type.ContentTypeParticle != null && type.ContentType == XmlSchemaContentType.Empty;
}
like image 160
gwiazdorrr Avatar answered Oct 15 '22 10:10

gwiazdorrr


I'd tried the same solution as you, but it's messy alright. Just about to try: http://www.c-sharpcorner.com/Forums/Thread/54685/detecting-xmlschemacomplextype-contentparticletype-is-equal.aspx

like image 35
PJM Avatar answered Oct 15 '22 09:10

PJM


I think that you should consider any ContentTypeParticle with MaxOccurs == 0 to be empty.

like image 41
Mårten Wikström Avatar answered Oct 15 '22 09:10

Mårten Wikström