Help: Simple example of parsing a ComplexType? [message #13777] |
Mon, 17 March 2003 10:18 |
Eclipse User |
|
|
|
Originally posted by: john.infonomicon.com
Hello all,
I _think_ I understand the basics of using the Infoset, and I have read the
provided article and FAQ. However, I am still completely at a loss as to how
I would examine the contents of an <xs:complexType>. For example, if I have
an element that comprises four sub-elements derived from type <xs:string>,
how could I programmatically determine their restrictions/enumerations etc?
Does anyone have a simple code snippet/example which would illustrate usage?
Thanks in advance,
John.
|
|
|
Re: Help: Simple example of parsing a ComplexType? [message #13797 is a reply to message #13777] |
Mon, 17 March 2003 12:56 |
Eclipse User |
|
|
|
Originally posted by: merks.ca.ibm.com
John,
Here's snippet of code that does some of the things you mention:
void handle(XSDElementDeclaration xsdElementDeclaration)
{
XSDTypeDefinition xsdTypeDefinition =
xsdElementDeclaration.getTypeDefinition();
if (xsdTypeDefinition instanceof XSDSimpleTypeDefinition)
{
XSDSimpleTypeDefinition xsdSimpleTypeDefinition =
(XSDSimpleTypeDefinition)xsdTypeDefinition;
for (Iterator i = xsdSimpleTypeDefinition.getFacets().iterator();
i.hasNext(); )
{
XSDFacet xsdFacet = (XSDFacet)i.next();
if (xsdFacet instanceof XSDEnumerationFacet)
{
for (Iterator j =
((XSDEnumerationFacet)xsdFacet).getValue().iterator(); j.hasNext(); )
{
Object enumerator = j.next();
}
}
else if (xsdFacet instanceof XSDPatternFacet)
{
}
// ...
}
}
else
{
XSDComplexTypeDefinition xsdComplexTypeDefinition =
(XSDComplexTypeDefinition)xsdTypeDefinition;
switch (xsdComplexTypeDefinition.getContentTypeCategory().getValue( ))
{
case XSDContentTypeCategory.EMPTY:
{
break;
}
case XSDContentTypeCategory.SIMPLE:
{
XSDSimpleTypeDefinition xsdSimpleTypeDefinition =
(XSDSimpleTypeDefinition)xsdComplexTypeDefinition.getContent Type();
break;
}
case XSDContentTypeCategory.ELEMENT_ONLY:
case XSDContentTypeCategory.MIXED:
{
XSDParticle xsdParticle =
(XSDParticle)xsdComplexTypeDefinition.getContentType();
XSDTerm xsdTerm = xsdParticle.getTerm();
if (xsdTerm instanceof XSDModelGroup)
{
XSDModelGroup xsdModelGroup = (XSDModelGroup)xsdTerm;
for (Iterator i = xsdModelGroup.getParticles().iterator();
i.hasNext(); )
{
XSDParticle childXSDParticle = (XSDParticle)i.next();
}
}
else if (xsdTerm instanceof XSDElementDeclaration)
{
}
else if (xsdTerm instanceof XSDWildcard)
{
}
break;
}
}
}
}
It's an unfortunate fact of life that XML Schema is incredibly complicated...
John McDonnell wrote:
> Hello all,
>
> I _think_ I understand the basics of using the Infoset, and I have read the
> provided article and FAQ. However, I am still completely at a loss as to how
> I would examine the contents of an <xs:complexType>. For example, if I have
> an element that comprises four sub-elements derived from type <xs:string>,
> how could I programmatically determine their restrictions/enumerations etc?
>
> Does anyone have a simple code snippet/example which would illustrate usage?
>
> Thanks in advance,
>
> John.
|
|
|
|
Re: Help: Simple example of parsing a ComplexType? [message #566343 is a reply to message #13777] |
Mon, 17 March 2003 12:56 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
John,
Here's snippet of code that does some of the things you mention:
void handle(XSDElementDeclaration xsdElementDeclaration)
{
XSDTypeDefinition xsdTypeDefinition =
xsdElementDeclaration.getTypeDefinition();
if (xsdTypeDefinition instanceof XSDSimpleTypeDefinition)
{
XSDSimpleTypeDefinition xsdSimpleTypeDefinition =
(XSDSimpleTypeDefinition)xsdTypeDefinition;
for (Iterator i = xsdSimpleTypeDefinition.getFacets().iterator();
i.hasNext(); )
{
XSDFacet xsdFacet = (XSDFacet)i.next();
if (xsdFacet instanceof XSDEnumerationFacet)
{
for (Iterator j =
((XSDEnumerationFacet)xsdFacet).getValue().iterator(); j.hasNext(); )
{
Object enumerator = j.next();
}
}
else if (xsdFacet instanceof XSDPatternFacet)
{
}
// ...
}
}
else
{
XSDComplexTypeDefinition xsdComplexTypeDefinition =
(XSDComplexTypeDefinition)xsdTypeDefinition;
switch (xsdComplexTypeDefinition.getContentTypeCategory().getValue( ))
{
case XSDContentTypeCategory.EMPTY:
{
break;
}
case XSDContentTypeCategory.SIMPLE:
{
XSDSimpleTypeDefinition xsdSimpleTypeDefinition =
(XSDSimpleTypeDefinition)xsdComplexTypeDefinition.getContent Type();
break;
}
case XSDContentTypeCategory.ELEMENT_ONLY:
case XSDContentTypeCategory.MIXED:
{
XSDParticle xsdParticle =
(XSDParticle)xsdComplexTypeDefinition.getContentType();
XSDTerm xsdTerm = xsdParticle.getTerm();
if (xsdTerm instanceof XSDModelGroup)
{
XSDModelGroup xsdModelGroup = (XSDModelGroup)xsdTerm;
for (Iterator i = xsdModelGroup.getParticles().iterator();
i.hasNext(); )
{
XSDParticle childXSDParticle = (XSDParticle)i.next();
}
}
else if (xsdTerm instanceof XSDElementDeclaration)
{
}
else if (xsdTerm instanceof XSDWildcard)
{
}
break;
}
}
}
}
It's an unfortunate fact of life that XML Schema is incredibly complicated...
John McDonnell wrote:
> Hello all,
>
> I _think_ I understand the basics of using the Infoset, and I have read the
> provided article and FAQ. However, I am still completely at a loss as to how
> I would examine the contents of an <xs:complexType>. For example, if I have
> an element that comprises four sub-elements derived from type <xs:string>,
> how could I programmatically determine their restrictions/enumerations etc?
>
> Does anyone have a simple code snippet/example which would illustrate usage?
>
> Thanks in advance,
>
> John.
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Powered by
FUDForum. Page generated in 0.02862 seconds