Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » XML Schema Definition (XSD) » Help: Simple example of parsing a ComplexType?
Help: Simple example of parsing a ComplexType? [message #13777] Mon, 17 March 2003 05:18 Go to next message
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 07:56 Go to previous messageGo to next message
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 #13817 is a reply to message #13797] Mon, 17 March 2003 15:42 Go to previous message
Eclipse User
Originally posted by: john.infonomicon.com

"Ed Merks" <merks@ca.ibm.com> wrote in message
news:3E75C602.77C8805A@ca.ibm.com...
> John,
>
Much goodness snipped!
>
> It's an unfortunate fact of life that XML Schema is incredibly
complicated...
>
>
> John McDonnell wrote:
>

Thanks to Ed and his example, my problems are solved :). Though a little
knowledge is a dangerous thing, I think I feel an article coming on...

Cheers,

John.
Re: Help: Simple example of parsing a ComplexType? [message #566343 is a reply to message #13777] Mon, 17 March 2003 07:56 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 25919
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.
Re: Help: Simple example of parsing a ComplexType? [message #566371 is a reply to message #13797] Mon, 17 March 2003 15:42 Go to previous message
John McDonnell is currently offline John McDonnell
Messages: 2
Registered: July 2009
Junior Member
"Ed Merks" <merks@ca.ibm.com> wrote in message
news:3E75C602.77C8805A@ca.ibm.com...
> John,
>
Much goodness snipped!
>
> It's an unfortunate fact of life that XML Schema is incredibly
complicated...
>
>
> John McDonnell wrote:
>

Thanks to Ed and his example, my problems are solved :). Though a little
knowledge is a dangerous thing, I think I feel an article coming on...

Cheers,

John.
Previous Topic:Help: Simple example of parsing a ComplexType?
Next Topic:Retrieving the line number from XSDDiagnostic
Goto Forum:
  


Current Time: Fri Jul 25 19:07:41 EDT 2014

Powered by FUDForum. Page generated in 0.01736 seconds