Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » XML Schema Definition (XSD) » How to find "root" element in a schema. Check if an element is referenced
How to find "root" element in a schema. Check if an element is referenced [message #50579] Wed, 18 August 2004 22:41 Go to next message
Eclipse UserFriend
Originally posted by: gj.puredge.com

Hi,

I have a schema loaded into an XSDSchema model which consists of a lot of
element definitions of which only one is the root element for my document.

In this case all the elements are defined "globally" (sorry if that's the
incorrect term) and then referenced in other element definitions. For
example: <xs:element ref="title" /> where "title" is declared elsewhere.

I understand that there need not be a concept of a root element since schema
simply defines elements that can be present in a document. In this
particular case the schema defines a single document and there really is a
root element. The "root" element should be the only one which is not
referred to by anything else. Does this sound resonable?

I process the schema by fetching all the Element Declarations:

EList elements = schema.getSchema().getElementDeclarations()

and processing each one.

for (Iterator iter = elements.iterator(); iter.hasNext(); )
{
XSDElementDeclaration element = (XSDElementDeclaration)iter.next();

// Check if this is the root element
boolean flag = isReferenced(element, schema);
}

Assuming that this is the correct approach how can I easily find out if a
given element is referenced by another element in the schema? In other
words I need an isReferenced() method.

Does anyone have any ideas or am I so far off track it isn't funny?

Thanks

Gary
Re: How to find "root" element in a schema. Check if an element is referenced [message #50637 is a reply to message #50579] Thu, 19 August 2004 10:26 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Gary,

This sounds reasonable. You can use
org.eclipse.xsd.util.XSDUtil.UsageCrossReferencer to find all
references. Note that getElementDeclarations returns all element
declarations, including imported ones.


Gary J wrote:

>Hi,
>
>I have a schema loaded into an XSDSchema model which consists of a lot of
>element definitions of which only one is the root element for my document.
>
>In this case all the elements are defined "globally" (sorry if that's the
>incorrect term) and then referenced in other element definitions. For
>example: <xs:element ref="title" /> where "title" is declared elsewhere.
>
>I understand that there need not be a concept of a root element since schema
>simply defines elements that can be present in a document. In this
>particular case the schema defines a single document and there really is a
>root element. The "root" element should be the only one which is not
>referred to by anything else. Does this sound resonable?
>
>I process the schema by fetching all the Element Declarations:
>
>EList elements = schema.getSchema().getElementDeclarations()
>
>and processing each one.
>
>for (Iterator iter = elements.iterator(); iter.hasNext(); )
> {
> XSDElementDeclaration element = (XSDElementDeclaration)iter.next();
>
> // Check if this is the root element
> boolean flag = isReferenced(element, schema);
> }
>
>Assuming that this is the correct approach how can I easily find out if a
>given element is referenced by another element in the schema? In other
>words I need an isReferenced() method.
>
>Does anyone have any ideas or am I so far off track it isn't funny?
>
>Thanks
>
>Gary
>
>
>
>
>
Re: How to find "root" element in a schema. Check if an element is referenced [message #50694 is a reply to message #50637] Thu, 19 August 2004 18:00 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: gj.puredge.com

Thanks Ed,

I tried it on a simple schema and got back a collection in both cases where
the element was referenced and where it was not.

Here's what I did:

EList elements = schema.getSchema().getElementDeclarations();
for (Iterator iter = elements.iterator(); iter.hasNext();)
{
XSDElementDeclaration element = (XSDElementDeclaration)iter.next();

// Test if element referenced
ArrayList list = (ArrayList)UsageCrossReferencer.find(element, elements);
}

The schema looks like this: (its the standard po example - file7)

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="PurchaseOrderType">
...
<xsd:element minOccurs="0" ref="comment"></xsd:element>
...
</xsd:complexType>
<xsd:element name="purchaseOrder" type="PurchaseOrderType"></xsd:element>
<xsd:element name="comment" type="xsd:string"></xsd:element>
</xsd:schema>

I get back two elements and check each one for referenced. Sorry if I'm
totally stupid. How do I determine that the element comment is referenced
by the element purchaseOrder? I've looked everywhere in 'list' in debug but
can not find anything.

Thanks
Re: How to find "root" element in a schema. Check if an element is referenced [message #50722 is a reply to message #50694] Thu, 19 August 2004 19:09 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: user.domain.invalid

How do I determine that the element comment is referenced by the element
purchaseOrder? look at the schema.
1. the element with name="purchaseOrder" is of type="PurchaseOrderType"
2. xsd:complexType name="PurchaseOrderType" contains an element with
ref="comment", a reference to the element comment.

norwood sisson

Gary J wrote:
> Thanks Ed,
>
> I tried it on a simple schema and got back a collection in both cases where
> the element was referenced and where it was not.
>
> Here's what I did:
>
> EList elements = schema.getSchema().getElementDeclarations();
> for (Iterator iter = elements.iterator(); iter.hasNext();)
> {
> XSDElementDeclaration element = (XSDElementDeclaration)iter.next();
>
> // Test if element referenced
> ArrayList list = (ArrayList)UsageCrossReferencer.find(element, elements);
> }
>
> The schema looks like this: (its the standard po example - file7)
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
> <xsd:complexType name="PurchaseOrderType">
> ...
> <xsd:element minOccurs="0" ref="comment"></xsd:element>
> ...
> </xsd:complexType>
> <xsd:element name="purchaseOrder" type="PurchaseOrderType"></xsd:element>
> <xsd:element name="comment" type="xsd:string"></xsd:element>
> </xsd:schema>
>
> I get back two elements and check each one for referenced. Sorry if I'm
> totally stupid. How do I determine that the element comment is referenced
> by the element purchaseOrder? I've looked everywhere in 'list' in debug but
> can not find anything.
>
> Thanks
Re: How to find "root" element in a schema. Check if an element is referenced [message #50777 is a reply to message #50637] Thu, 19 August 2004 19:12 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: gj.puredge.com

I think I answered part of my own question. I was only checking Element
declarations, not types. I'm now checking both and get back a larger list
for "comments".

Is there any documentation about what I should be seeing in these lists?

Here's my code:

EList elements = schema.getSchema().getElementDeclarations();
EList types = schema.getSchema().getTypeDefinitions();

for (Iterator iter = elements.iterator(); iter.hasNext();)
{
XSDElementDeclaration element = (XSDElementDeclaration)iter.next();
System.out.println(" Element: " + element.getName());

ArrayList elist = (ArrayList)UsageCrossReferencer.find(element,
elements);

// list contents of element references
for (Iterator i = elist.iterator(); i.hasNext();)
{
Object obj = i.next();
System.out.println(" Element ref: " + obj.getClass());
}

ArrayList tlist = (ArrayList)UsageCrossReferencer.find(element, types);

// list contents of type references
for (Iterator i = tlist.iterator(); i.hasNext();)
{
Object obj = i.next();
System.out.println(" Type ref: " + obj.getClass());
}

}

Here's what I get:

For the "comment" element I get:
Element: comment
Element ref: class org.eclipse.emf.ecore.impl.BasicEObjectImpl$2
Element ref: class org.eclipse.emf.ecore.util.EObjectEList

Type ref: class org.eclipse.emf.ecore.impl.BasicEObjectImpl$2
Type ref: class org.eclipse.emf.ecore.impl.BasicEObjectImpl$2
Type ref: class org.eclipse.emf.ecore.impl.BasicEObjectImpl$2
Type ref: class org.eclipse.emf.ecore.impl.BasicEObjectImpl$2

For the "purchaseOrder" element I get:
Element: purchaseOrder
Element ref: class org.eclipse.emf.ecore.impl.BasicEObjectImpl$2
Element ref: class org.eclipse.emf.ecore.util.EObjectEList

How do I decode all this?

Thanks

Gary

"Ed Merks" <merks@ca.ibm.com> wrote in message
news:cg1v5q$fu2$1@eclipse.org...
> Gary,
>
> This sounds reasonable. You can use
> org.eclipse.xsd.util.XSDUtil.UsageCrossReferencer to find all
> references. Note that getElementDeclarations returns all element
> declarations, including imported ones.
>
>
> Gary J wrote:
>
> >Hi,
> >
> >I have a schema loaded into an XSDSchema model which consists of a lot of
> >element definitions of which only one is the root element for my
document.
> >
> >In this case all the elements are defined "globally" (sorry if that's the
> >incorrect term) and then referenced in other element definitions. For
> >example: <xs:element ref="title" /> where "title" is declared
elsewhere.
> >
> >I understand that there need not be a concept of a root element since
schema
> >simply defines elements that can be present in a document. In this
> >particular case the schema defines a single document and there really is
a
> >root element. The "root" element should be the only one which is not
> >referred to by anything else. Does this sound resonable?
> >
> >I process the schema by fetching all the Element Declarations:
> >
> >EList elements = schema.getSchema().getElementDeclarations()
> >
> >and processing each one.
> >
> >for (Iterator iter = elements.iterator(); iter.hasNext(); )
> > {
> > XSDElementDeclaration element = (XSDElementDeclaration)iter.next();
> >
> > // Check if this is the root element
> > boolean flag = isReferenced(element, schema);
> > }
> >
> >Assuming that this is the correct approach how can I easily find out if a
> >given element is referenced by another element in the schema? In other
> >words I need an isReferenced() method.
> >
> >Does anyone have any ideas or am I so far off track it isn't funny?
> >
> >Thanks
> >
> >Gary
> >
> >
> >
> >
> >
Re: How to find "root" element in a schema. Check if an element is referenced [message #50826 is a reply to message #50722] Thu, 19 August 2004 19:18 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: gj.puredge.com

Thanks, you are correct that it is all in the schema but I was talking about
the XML Infoset Model, not the .xsd text file.

In the Infoset model the schema is expressed in a model of java objects
which the user can query. How to perform the traversing and interpret the
results was my question.

<user@domain.invalid> wrote in message news:cg2tma$7fn$1@eclipse.org...
> How do I determine that the element comment is referenced by the element
> purchaseOrder? look at the schema.
> 1. the element with name="purchaseOrder" is of type="PurchaseOrderType"
> 2. xsd:complexType name="PurchaseOrderType" contains an element with
> ref="comment", a reference to the element comment.
>
> norwood sisson
>

<user@domain.invalid> wrote in message news:cg2tma$7fn$1@eclipse.org...
> How do I determine that the element comment is referenced by the element
> purchaseOrder? look at the schema.
> 1. the element with name="purchaseOrder" is of type="PurchaseOrderType"
> 2. xsd:complexType name="PurchaseOrderType" contains an element with
> ref="comment", a reference to the element comment.
>
> norwood sisson
>
> Gary J wrote:
> > Thanks Ed,
> >
> > I tried it on a simple schema and got back a collection in both cases
where
> > the element was referenced and where it was not.
> >
> > Here's what I did:
> >
> > EList elements = schema.getSchema().getElementDeclarations();
> > for (Iterator iter = elements.iterator(); iter.hasNext();)
> > {
> > XSDElementDeclaration element = (XSDElementDeclaration)iter.next();
> >
> > // Test if element referenced
> > ArrayList list = (ArrayList)UsageCrossReferencer.find(element,
elements);
> > }
> >
> > The schema looks like this: (its the standard po example - file7)
> >
> > <?xml version="1.0" encoding="UTF-8"?>
> > <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
> > <xsd:complexType name="PurchaseOrderType">
> > ...
> > <xsd:element minOccurs="0" ref="comment"></xsd:element>
> > ...
> > </xsd:complexType>
> > <xsd:element name="purchaseOrder"
type="PurchaseOrderType"></xsd:element>
> > <xsd:element name="comment" type="xsd:string"></xsd:element>
> > </xsd:schema>
> >
> > I get back two elements and check each one for referenced. Sorry if I'm
> > totally stupid. How do I determine that the element comment is
referenced
> > by the element purchaseOrder? I've looked everywhere in 'list' in debug
but
> > can not find anything.
> >
> > Thanks
Re: How to find "root" element in a schema. Check if an element is referenced [message #50854 is a reply to message #50777] Thu, 19 August 2004 19:55 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

This is a multi-part message in MIME format.
--------------090206070101090509000002
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Gary,

You should be doing the find against the whole resource set, the whole
resource, or the whole schema, not just against the list of elements or
the list of types. The objects in the list are of type
org.eclipse.emf.ecore.EStructuralFeature.Setting from which you can
determine the object doing the referencing as well as the feature of the
object that holds the reference. Only the base class in EMF
(EcoreUtil.UsageCrossReferencer) has javadoc...


Gary J wrote:

>I think I answered part of my own question. I was only checking Element
>declarations, not types. I'm now checking both and get back a larger list
>for "comments".
>
>Is there any documentation about what I should be seeing in these lists?
>
>Here's my code:
>
> EList elements = schema.getSchema().getElementDeclarations();
> EList types = schema.getSchema().getTypeDefinitions();
>
> for (Iterator iter = elements.iterator(); iter.hasNext();)
> {
> XSDElementDeclaration element = (XSDElementDeclaration)iter.next();
> System.out.println(" Element: " + element.getName());
>
> ArrayList elist = (ArrayList)UsageCrossReferencer.find(element,
>elements);
>
> // list contents of element references
> for (Iterator i = elist.iterator(); i.hasNext();)
> {
> Object obj = i.next();
> System.out.println(" Element ref: " + obj.getClass());
> }
>
> ArrayList tlist = (ArrayList)UsageCrossReferencer.find(element, types);
>
> // list contents of type references
> for (Iterator i = tlist.iterator(); i.hasNext();)
> {
> Object obj = i.next();
> System.out.println(" Type ref: " + obj.getClass());
> }
>
> }
>
>Here's what I get:
>
>For the "comment" element I get:
>Element: comment
>Element ref: class org.eclipse.emf.ecore.impl.BasicEObjectImpl$2
>Element ref: class org.eclipse.emf.ecore.util.EObjectEList
>
>Type ref: class org.eclipse.emf.ecore.impl.BasicEObjectImpl$2
>Type ref: class org.eclipse.emf.ecore.impl.BasicEObjectImpl$2
>Type ref: class org.eclipse.emf.ecore.impl.BasicEObjectImpl$2
>Type ref: class org.eclipse.emf.ecore.impl.BasicEObjectImpl$2
>
>For the "purchaseOrder" element I get:
>Element: purchaseOrder
>Element ref: class org.eclipse.emf.ecore.impl.BasicEObjectImpl$2
>Element ref: class org.eclipse.emf.ecore.util.EObjectEList
>
>How do I decode all this?
>
>Thanks
>
>Gary
>
>"Ed Merks" <merks@ca.ibm.com> wrote in message
>news:cg1v5q$fu2$1@eclipse.org...
>
>
>>Gary,
>>
>>This sounds reasonable. You can use
>>org.eclipse.xsd.util.XSDUtil.UsageCrossReferencer to find all
>>references. Note that getElementDeclarations returns all element
>>declarations, including imported ones.
>>
>>
>>Gary J wrote:
>>
>>
>>
>>>Hi,
>>>
>>>I have a schema loaded into an XSDSchema model which consists of a lot of
>>>element definitions of which only one is the root element for my
>>>
>>>
>document.
>
>
>>>In this case all the elements are defined "globally" (sorry if that's the
>>>incorrect term) and then referenced in other element definitions. For
>>>example: <xs:element ref="title" /> where "title" is declared
>>>
>>>
>elsewhere.
>
>
>>>I understand that there need not be a concept of a root element since
>>>
>>>
>schema
>
>
>>>simply defines elements that can be present in a document. In this
>>>particular case the schema defines a single document and there really is
>>>
>>>
>a
>
>
>>>root element. The "root" element should be the only one which is not
>>>referred to by anything else. Does this sound resonable?
>>>
>>>I process the schema by fetching all the Element Declarations:
>>>
>>>EList elements = schema.getSchema().getElementDeclarations()
>>>
>>>and processing each one.
>>>
>>>for (Iterator iter = elements.iterator(); iter.hasNext(); )
>>> {
>>> XSDElementDeclaration element = (XSDElementDeclaration)iter.next();
>>>
>>> // Check if this is the root element
>>> boolean flag = isReferenced(element, schema);
>>> }
>>>
>>>Assuming that this is the correct approach how can I easily find out if a
>>>given element is referenced by another element in the schema? In other
>>>words I need an isReferenced() method.
>>>
>>>Does anyone have any ideas or am I so far off track it isn't funny?
>>>
>>>Thanks
>>>
>>>Gary
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>
>
>
>


--------------090206070101090509000002
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Gary,<br>
<br>
You should be doing the find against the whole resource set, the whole
resource, or the whole schema, not just against the list of elements or
the list of types.&nbsp; The objects in the list are of type
org.eclipse.emf.ecore.EStructuralFeature.Setting from which you can
determine the object doing the referencing as well as the feature of
the object that holds the reference.&nbsp; Only the base class in EMF
(EcoreUtil.UsageCrossReferencer) has javadoc...<br>
<br>
<br>
Gary J wrote:<br>
<blockquote cite="midcg2tt0$7ps$1@eclipse.org" type="cite">
<pre wrap="">I think I answered part of my own question. I was only checking Element
declarations, not types. I'm now checking both and get back a larger list
for "comments".

Is there any documentation about what I should be seeing in these lists?

Here's my code:

EList elements = schema.getSchema().getElementDeclarations();
EList types = schema.getSchema().getTypeDefinitions();

for (Iterator iter = elements.iterator(); iter.hasNext();)
{
XSDElementDeclaration element = (XSDElementDeclaration)iter.next();
System.out.println(" Element: " + element.getName());

ArrayList elist = (ArrayList)UsageCrossReferencer.find(element,
elements);

// list contents of element references
for (Iterator i = elist.iterator(); i.hasNext();)
{
Object obj = i.next();
System.out.println(" Element ref: " + obj.getClass());
}

ArrayList tlist = (ArrayList)UsageCrossReferencer.find(element, types);

// list contents of type references
for (Iterator i = tlist.iterator(); i.hasNext();)
{
Object obj = i.next();
System.out.println(" Type ref: " + obj.getClass());
}

}

Here's what I get:

For the "comment" element I get:
Element: comment
Element ref: class org.eclipse.emf.ecore.impl.BasicEObjectImpl$2
Element ref: class org.eclipse.emf.ecore.util.EObjectEList

Type ref: class org.eclipse.emf.ecore.impl.BasicEObjectImpl$2
Type ref: class org.eclipse.emf.ecore.impl.BasicEObjectImpl$2
Type ref: class org.eclipse.emf.ecore.impl.BasicEObjectImpl$2
Type ref: class org.eclipse.emf.ecore.impl.BasicEObjectImpl$2

For the "purchaseOrder" element I get:
Element: purchaseOrder
Element ref: class org.eclipse.emf.ecore.impl.BasicEObjectImpl$2
Element ref: class org.eclipse.emf.ecore.util.EObjectEList

How do I decode all this?

Thanks

Gary

"Ed Merks" <a class="moz-txt-link-rfc2396E" href="mailto:merks@ca.ibm.com">&lt;merks@ca.ibm.com&gt;</a> wrote in message
<a class="moz-txt-link-freetext" href="news:cg1v5q$fu2$1@eclipse.org">news:cg1v5q$fu2$1@eclipse.org</a>...
</pre>
<blockquote type="cite">
<pre wrap="">Gary,

This sounds reasonable. You can use
org.eclipse.xsd.util.XSDUtil.UsageCrossReferencer to find all
references. Note that getElementDeclarations returns all element
declarations, including imported ones.


Gary J wrote:

</pre>
<blockquote type="cite">
<pre wrap="">Hi,

I have a schema loaded into an XSDSchema model which consists of a lot of
element definitions of which only one is the root element for my
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->document.
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">In this case all the elements are defined "globally" (sorry if that's the
incorrect term) and then referenced in other element definitions. For
example: &lt;xs:element ref="title" /&gt; where "title" is declared
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->elsewhere.
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">I understand that there need not be a concept of a root element since
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->schema
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">simply defines elements that can be present in a document. In this
particular case the schema defines a single document and there really is
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->a
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">root element. The "root" element should be the only one which is not
referred to by anything else. Does this sound resonable?

I process the schema by fetching all the Element Declarations:

EList elements = schema.getSchema().getElementDeclarations()

and processing each one.

for (Iterator iter = elements.iterator(); iter.hasNext(); )
{
XSDElementDeclaration element = (XSDElementDeclaration)iter.next();

// Check if this is the root element
boolean flag = isReferenced(element, schema);
}

Assuming that this is the correct approach how can I easily find out if a
given element is referenced by another element in the schema? In other
words I need an isReferenced() method.

Does anyone have any ideas or am I so far off track it isn't funny?

Thanks

Gary





</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->

</pre>
</blockquote>
<br>
</body>
</html>

--------------090206070101090509000002--
Re: How to find "root" element in a schema. Check if an element is referenced [message #50881 is a reply to message #50854] Thu, 19 August 2004 21:30 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: gj.puredge.com

Thanks Ed,

Once I used the schema to compare against all seems to work. For anyone
else who's interested, here's what I did. Is this a reasonable approach?

EList elements = schema.getSchema().getElementDeclarations();
for (Iterator iter = elements.iterator(); iter.hasNext();)
{
XSDElementDeclaration element = (XSDElementDeclaration) iter.next();
if (!isReferenced(element, schema))
{
System.out.println(" Element: <" + element.getName() + "> is a root
element.");
}
}

------------------

boolean isReferenced(XSDElementDeclaration element, XSDSchema schema)
{
int count = 0;

// Determine how many references there are to this element
ArrayList list = (ArrayList) UsageCrossReferencer.find(element, schema);
for (Iterator i = list.iterator(); i.hasNext();)
{
Setting setting = (Setting) i.next();
EObject obj = setting.getEObject();
if (obj != schema && obj != element)
count++;
}

return count > 0 ? false : true;
}


Note I think this also counts references in types that might not themselves
be referenced by elements. A more exact method might be to check for
element references when obj (above) is a particle. Does that sound right?

Gary
Re: How to find "root" element in a schema. Check if an element is referenced [message #50910 is a reply to message #50881] Thu, 19 August 2004 21:40 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: gj.puredge.com

minor correction.

return count > 0 ? false : true;

shoud be

return count > 0 ? true : false;



"Gary J" <gj@puredge.com> wrote in message news:cg360c$k1f$1@eclipse.org...
> Thanks Ed,
>
> Once I used the schema to compare against all seems to work. For anyone
> else who's interested, here's what I did. Is this a reasonable approach?
>
> EList elements = schema.getSchema().getElementDeclarations();
> for (Iterator iter = elements.iterator(); iter.hasNext();)
> {
> XSDElementDeclaration element = (XSDElementDeclaration) iter.next();
> if (!isReferenced(element, schema))
> {
> System.out.println(" Element: <" + element.getName() + "> is a root
> element.");
> }
> }
>
> ------------------
>
> boolean isReferenced(XSDElementDeclaration element, XSDSchema schema)
> {
> int count = 0;
>
> // Determine how many references there are to this element
> ArrayList list = (ArrayList) UsageCrossReferencer.find(element, schema);
> for (Iterator i = list.iterator(); i.hasNext();)
> {
> Setting setting = (Setting) i.next();
> EObject obj = setting.getEObject();
> if (obj != schema && obj != element)
> count++;
> }
>
> return count > 0 ? false : true;
> }
>
>
> Note I think this also counts references in types that might not
themselves
> be referenced by elements. A more exact method might be to check for
> element references when obj (above) is a particle. Does that sound right?
>
> Gary
>
>
Re: How to find "root" element in a schema. Check if an element is referenced [message #50937 is a reply to message #50881] Thu, 19 August 2004 21:45 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Gary,

Yes this looks reasonable. I think you are right that an element must
be referenced from a particle in order to be in a content model of
something. The two cases you filtered out (I think) are for the schema
referencing the element in the getElementDeclarations, and the element
referencing itself in the getResolvedElementDeclaration. Note that an
element may reference another element with
getSubstitutionGroupAffiliation. Looking at the feature of the Setting
will help tell you how the object is referencing the element. Note that
something like XSDPackage.eINSTANCE.getXSDParticle_Term() will give you
access to the feature for comparing against the feature you see in the
Setting.


Gary J wrote:

>Thanks Ed,
>
>Once I used the schema to compare against all seems to work. For anyone
>else who's interested, here's what I did. Is this a reasonable approach?
>
> EList elements = schema.getSchema().getElementDeclarations();
> for (Iterator iter = elements.iterator(); iter.hasNext();)
> {
> XSDElementDeclaration element = (XSDElementDeclaration) iter.next();
> if (!isReferenced(element, schema))
> {
> System.out.println(" Element: <" + element.getName() + "> is a root
>element.");
> }
> }
>
>------------------
>
> boolean isReferenced(XSDElementDeclaration element, XSDSchema schema)
> {
> int count = 0;
>
> // Determine how many references there are to this element
> ArrayList list = (ArrayList) UsageCrossReferencer.find(element, schema);
> for (Iterator i = list.iterator(); i.hasNext();)
> {
> Setting setting = (Setting) i.next();
> EObject obj = setting.getEObject();
> if (obj != schema && obj != element)
> count++;
> }
>
> return count > 0 ? false : true;
> }
>
>
>Note I think this also counts references in types that might not themselves
>be referenced by elements. A more exact method might be to check for
>element references when obj (above) is a particle. Does that sound right?
>
>Gary
>
>
>
>
Re: How to find "root" element in a schema. Check if an element is referenced [message #50964 is a reply to message #50910] Thu, 19 August 2004 21:47 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

This is a multi-part message in MIME format.
--------------020506080505040006010506
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Gary,

This would be slightly more simple. ;-)

return count > 0;


Gary J wrote:

>minor correction.
>
>return count > 0 ? false : true;
>
>shoud be
>
>return count > 0 ? true : false;
>
>
>
>"Gary J" <gj@puredge.com> wrote in message news:cg360c$k1f$1@eclipse.org...
>
>
>>Thanks Ed,
>>
>>Once I used the schema to compare against all seems to work. For anyone
>>else who's interested, here's what I did. Is this a reasonable approach?
>>
>> EList elements = schema.getSchema().getElementDeclarations();
>> for (Iterator iter = elements.iterator(); iter.hasNext();)
>> {
>> XSDElementDeclaration element = (XSDElementDeclaration) iter.next();
>> if (!isReferenced(element, schema))
>> {
>> System.out.println(" Element: <" + element.getName() + "> is a root
>>element.");
>> }
>> }
>>
>>------------------
>>
>> boolean isReferenced(XSDElementDeclaration element, XSDSchema schema)
>> {
>> int count = 0;
>>
>> // Determine how many references there are to this element
>> ArrayList list = (ArrayList) UsageCrossReferencer.find(element, schema);
>> for (Iterator i = list.iterator(); i.hasNext();)
>> {
>> Setting setting = (Setting) i.next();
>> EObject obj = setting.getEObject();
>> if (obj != schema && obj != element)
>> count++;
>> }
>>
>> return count > 0 ? false : true;
>> }
>>
>>
>>Note I think this also counts references in types that might not
>>
>>
>themselves
>
>
>>be referenced by elements. A more exact method might be to check for
>>element references when obj (above) is a particle. Does that sound right?
>>
>>Gary
>>
>>
>>
>>
>
>
>
>


--------------020506080505040006010506
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Gary,<br>
<br>
This would be slightly more simple. ;-)<br>
<br>
<blockquote>&nbsp; return count &gt; 0;<br>
</blockquote>
<br>
Gary J wrote:<br>
<blockquote cite="midcg36j6$kqa$1@eclipse.org" type="cite">
<pre wrap="">minor correction.

return count &gt; 0 ? false : true;

shoud be

return count &gt; 0 ? true : false;



"Gary J" <a class="moz-txt-link-rfc2396E" href="mailto:gj@puredge.com">&lt;gj@puredge.com&gt;</a> wrote in message <a class="moz-txt-link-freetext" href="news:cg360c$k1f$1@eclipse.org">news:cg360c$k1f$1@eclipse.org</a>...
</pre>
<blockquote type="cite">
<pre wrap="">Thanks Ed,

Once I used the schema to compare against all seems to work. For anyone
else who's interested, here's what I did. Is this a reasonable approach?

EList elements = schema.getSchema().getElementDeclarations();
for (Iterator iter = elements.iterator(); iter.hasNext();)
{
XSDElementDeclaration element = (XSDElementDeclaration) iter.next();
if (!isReferenced(element, schema))
{
System.out.println(" Element: &lt;" + element.getName() + "&gt; is a root
element.");
}
}

------------------

boolean isReferenced(XSDElementDeclaration element, XSDSchema schema)
{
int count = 0;

// Determine how many references there are to this element
ArrayList list = (ArrayList) UsageCrossReferencer.find(element, schema);
for (Iterator i = list.iterator(); i.hasNext();)
{
Setting setting = (Setting) i.next();
EObject obj = setting.getEObject();
if (obj != schema &amp;&amp; obj != element)
count++;
}

return count &gt; 0 ? false : true;
}


Note I think this also counts references in types that might not
</pre>
</blockquote>
<pre wrap=""><!---->themselves
</pre>
<blockquote type="cite">
<pre wrap="">be referenced by elements. A more exact method might be to check for
element references when obj (above) is a particle. Does that sound right?

Gary


</pre>
</blockquote>
<pre wrap=""><!---->

</pre>
</blockquote>
<br>
</body>
</html>

--------------020506080505040006010506--
Re: How to find "root" element in a schema. Check if an element is referenced [message #50992 is a reply to message #50937] Thu, 19 August 2004 22:59 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: gj.puredge.com

I have one more problem which is more related to performance. I have a
large schema with 15000+ lines of element declarations. When I search for
the root elements it takes an extremely long time.

I have looked at the code for XSDUtil.UsageCrossReferencer.find() and it
seems that a new UsageCrossReferencer(schema) Collection is created for
every find().

Is there a way to speed this up by building the UsageCrossReferencer once
and re-using it for subsequent find()'s ?

UsageCrossReferencer is protected so I can not create an instance of it like
this:

UsageCrossReferencer xref = new UsageCrossReferencer(schema);

Should I subclass UsageCrossReferencer to solve this problem or is there a
better way?

Thanks

Gary



"Ed Merks" <merks@ca.ibm.com> wrote in message
news:cg36uk$l8k$1@eclipse.org...
> Gary,
>
> Yes this looks reasonable. I think you are right that an element must
> be referenced from a particle in order to be in a content model of
> something. The two cases you filtered out (I think) are for the schema
> referencing the element in the getElementDeclarations, and the element
> referencing itself in the getResolvedElementDeclaration. Note that an
> element may reference another element with
> getSubstitutionGroupAffiliation. Looking at the feature of the Setting
> will help tell you how the object is referencing the element. Note that
> something like XSDPackage.eINSTANCE.getXSDParticle_Term() will give you
> access to the feature for comparing against the feature you see in the
> Setting.
>
>
> Gary J wrote:
>
> >Thanks Ed,
> >
> >Once I used the schema to compare against all seems to work. For anyone
> >else who's interested, here's what I did. Is this a reasonable approach?
> >
> > EList elements = schema.getSchema().getElementDeclarations();
> > for (Iterator iter = elements.iterator(); iter.hasNext();)
> > {
> > XSDElementDeclaration element = (XSDElementDeclaration) iter.next();
> > if (!isReferenced(element, schema))
> > {
> > System.out.println(" Element: <" + element.getName() + "> is a root
> >element.");
> > }
> > }
> >
> >------------------
> >
> > boolean isReferenced(XSDElementDeclaration element, XSDSchema schema)
> > {
> > int count = 0;
> >
> > // Determine how many references there are to this element
> > ArrayList list = (ArrayList) UsageCrossReferencer.find(element,
schema);
> > for (Iterator i = list.iterator(); i.hasNext();)
> > {
> > Setting setting = (Setting) i.next();
> > EObject obj = setting.getEObject();
> > if (obj != schema && obj != element)
> > count++;
> > }
> >
> > return count > 0;
> > }
> >
> >
> >Note I think this also counts references in types that might not
themselves
> >be referenced by elements. A more exact method might be to check for
> >element references when obj (above) is a particle. Does that sound
right?
> >
> >Gary
> >
> >
> >
> >
Re: How to find "root" element in a schema. Check if an element is referenced [message #51020 is a reply to message #50992] Fri, 20 August 2004 00:28 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

This is a multi-part message in MIME format.
--------------030706010606050706060802
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Gary,

You should probably use findAll(xsdSchema.getElementDeclarations(),
xsdSchema) to find the usages of all the elements at once. The result
is a map from element to a Collection of Settings, i.e., the Collection
for a find of a single element. This way the whole schema is only
walked once.


Gary J wrote:

>I have one more problem which is more related to performance. I have a
>large schema with 15000+ lines of element declarations. When I search for
>the root elements it takes an extremely long time.
>
>I have looked at the code for XSDUtil.UsageCrossReferencer.find() and it
>seems that a new UsageCrossReferencer(schema) Collection is created for
>every find().
>
>Is there a way to speed this up by building the UsageCrossReferencer once
>and re-using it for subsequent find()'s ?
>
>UsageCrossReferencer is protected so I can not create an instance of it like
>this:
>
>UsageCrossReferencer xref = new UsageCrossReferencer(schema);
>
>Should I subclass UsageCrossReferencer to solve this problem or is there a
>better way?
>
>Thanks
>
>Gary
>
>
>
>"Ed Merks" <merks@ca.ibm.com> wrote in message
>news:cg36uk$l8k$1@eclipse.org...
>
>
>>Gary,
>>
>>Yes this looks reasonable. I think you are right that an element must
>>be referenced from a particle in order to be in a content model of
>>something. The two cases you filtered out (I think) are for the schema
>>referencing the element in the getElementDeclarations, and the element
>>referencing itself in the getResolvedElementDeclaration. Note that an
>>element may reference another element with
>>getSubstitutionGroupAffiliation. Looking at the feature of the Setting
>>will help tell you how the object is referencing the element. Note that
>>something like XSDPackage.eINSTANCE.getXSDParticle_Term() will give you
>>access to the feature for comparing against the feature you see in the
>>Setting.
>>
>>
>>Gary J wrote:
>>
>>
>>
>>>Thanks Ed,
>>>
>>>Once I used the schema to compare against all seems to work. For anyone
>>>else who's interested, here's what I did. Is this a reasonable approach?
>>>
>>>EList elements = schema.getSchema().getElementDeclarations();
>>> for (Iterator iter = elements.iterator(); iter.hasNext();)
>>> {
>>> XSDElementDeclaration element = (XSDElementDeclaration) iter.next();
>>> if (!isReferenced(element, schema))
>>> {
>>> System.out.println(" Element: <" + element.getName() + "> is a root
>>>element.");
>>> }
>>> }
>>>
>>>------------------
>>>
>>>boolean isReferenced(XSDElementDeclaration element, XSDSchema schema)
>>> {
>>> int count = 0;
>>>
>>> // Determine how many references there are to this element
>>> ArrayList list = (ArrayList) UsageCrossReferencer.find(element,
>>>
>>>
>schema);
>
>
>>> for (Iterator i = list.iterator(); i.hasNext();)
>>> {
>>> Setting setting = (Setting) i.next();
>>> EObject obj = setting.getEObject();
>>> if (obj != schema && obj != element)
>>> count++;
>>> }
>>>
>>> return count > 0;
>>> }
>>>
>>>
>>>Note I think this also counts references in types that might not
>>>
>>>
>themselves
>
>
>>>be referenced by elements. A more exact method might be to check for
>>>element references when obj (above) is a particle. Does that sound
>>>
>>>
>right?
>
>
>>>Gary
>>>
>>>
>>>
>>>
>>>
>>>
>
>
>
>


--------------030706010606050706060802
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Gary,<br>
<br>
You should&nbsp; probably use findAll(xsdSchema.getElementDeclarations(),
xsdSchema) to find the usages of all the elements at once.&nbsp; The result
is a map from element to a Collection of Settings, i.e., the Collection
for a find of a single element.&nbsp; This way the whole schema is only
walked once.<br>
<br>
<br>
Gary J wrote:<br>
<blockquote cite="midcg3b7e$pt3$1@eclipse.org" type="cite">
<pre wrap="">I have one more problem which is more related to performance. I have a
large schema with 15000+ lines of element declarations. When I search for
the root elements it takes an extremely long time.

I have looked at the code for XSDUtil.UsageCrossReferencer.find() and it
seems that a new UsageCrossReferencer(schema) Collection is created for
every find().

Is there a way to speed this up by building the UsageCrossReferencer once
and re-using it for subsequent find()'s ?

UsageCrossReferencer is protected so I can not create an instance of it like
this:

UsageCrossReferencer xref = new UsageCrossReferencer(schema);

Should I subclass UsageCrossReferencer to solve this problem or is there a
better way?

Thanks

Gary



"Ed Merks" <a class="moz-txt-link-rfc2396E" href="mailto:merks@ca.ibm.com">&lt;merks@ca.ibm.com&gt;</a> wrote in message
<a class="moz-txt-link-freetext" href="news:cg36uk$l8k$1@eclipse.org">news:cg36uk$l8k$1@eclipse.org</a>...
</pre>
<blockquote type="cite">
<pre wrap="">Gary,

Yes this looks reasonable. I think you are right that an element must
be referenced from a particle in order to be in a content model of
something. The two cases you filtered out (I think) are for the schema
referencing the element in the getElementDeclarations, and the element
referencing itself in the getResolvedElementDeclaration. Note that an
element may reference another element with
getSubstitutionGroupAffiliation. Looking at the feature of the Setting
will help tell you how the object is referencing the element. Note that
something like XSDPackage.eINSTANCE.getXSDParticle_Term() will give you
access to the feature for comparing against the feature you see in the
Setting.


Gary J wrote:

</pre>
<blockquote type="cite">
<pre wrap="">Thanks Ed,

Once I used the schema to compare against all seems to work. For anyone
else who's interested, here's what I did. Is this a reasonable approach?

EList elements = schema.getSchema().getElementDeclarations();
for (Iterator iter = elements.iterator(); iter.hasNext();)
{
XSDElementDeclaration element = (XSDElementDeclaration) iter.next();
if (!isReferenced(element, schema))
{
System.out.println(" Element: &lt;" + element.getName() + "&gt; is a root
element.");
}
}

------------------

boolean isReferenced(XSDElementDeclaration element, XSDSchema schema)
{
int count = 0;

// Determine how many references there are to this element
ArrayList list = (ArrayList) UsageCrossReferencer.find(element,
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->schema);
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap=""> for (Iterator i = list.iterator(); i.hasNext();)
{
Setting setting = (Setting) i.next();
EObject obj = setting.getEObject();
if (obj != schema &amp;&amp; obj != element)
count++;
}

return count &gt; 0;
}


Note I think this also counts references in types that might not
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->themselves
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">be referenced by elements. A more exact method might be to check for
element references when obj (above) is a particle. Does that sound
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->right?
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">Gary




</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->

</pre>
</blockquote>
<br>
</body>
</html>

--------------030706010606050706060802--
Re: How to find "root" element in a schema. Check if an element is referenced [message #51347 is a reply to message #51020] Tue, 24 August 2004 10:19 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: gnoutsa.hotmail.com

I Ed ,


>Ed Merks wrote:



> Gary,

> You should probably use findAll(xsdSchema.getElementDeclarations(),
> xsdSchema) to find the usages of all the elements at once. The result
> is a map from element to a Collection of Settings, i.e., the Collection
> for a find of a single element.

I don' t really understand what this map contain .
is that something like this : map("elementDeclarations","ArrayList")
please correct me if i' am wrong :
- the Key are all the Element "ElementDeclarations" retrieve
"directly"
from the Schema : sxdSchema.getElementDeclarations().
- the value is an "ArrayList" : what is the contain of this
"ArrayList" ?

is it possible that the map something else than ArrayList


> This way the whole schema is only
> walked once.


> Gary J wrote:

> >I have one more problem which is more related to performance. I have a
> >large schema with 15000+ lines of element declarations. When I search for
> >the root elements it takes an extremely long time.
> >
> >I have looked at the code for XSDUtil.UsageCrossReferencer.find() and it
> >seems that a new UsageCrossReferencer(schema) Collection is created for
> >every find().
> >
> >Is there a way to speed this up by building the UsageCrossReferencer once
> >and re-using it for subsequent find()'s ?
> >
> >UsageCrossReferencer is protected so I can not create an instance of it like
> >this:
> >
> >UsageCrossReferencer xref = new UsageCrossReferencer(schema);
> >
> >Should I subclass UsageCrossReferencer to solve this problem or is there a
> >better way?
> >
> >Thanks
> >
> >Gary
> >
> >
> >
> >"Ed Merks" <merks@ca.ibm.com> wrote in message
> >news:cg36uk$l8k$1@eclipse.org...
> >
> >
> >>Gary,
> >>
> >>Yes this looks reasonable. I think you are right that an element must
> >>be referenced from a particle in order to be in a content model of
> >>something. The two cases you filtered out (I think) are for the schema
> >>referencing the element in the getElementDeclarations, and the element
> >>referencing itself in the getResolvedElementDeclaration. Note that an
> >>element may reference another element with
> >>getSubstitutionGroupAffiliation. Looking at the feature of the Setting
> >>will help tell you how the object is referencing the element. Note that
> >>something like XSDPackage.eINSTANCE.getXSDParticle_Term() will give you
> >>access to the feature for comparing against the feature you see in the
> >>Setting.
> >>
> >>
> >>Gary J wrote:
> >>
> >>
> >>
> >>>Thanks Ed,
> >>>
> >>>Once I used the schema to compare against all seems to work. For anyone
> >>>else who's interested, here's what I did. Is this a reasonable approach?
> >>>
> >>>EList elements = schema.getSchema().getElementDeclarations();
> >>> for (Iterator iter = elements.iterator(); iter.hasNext();)
> >>> {
> >>> XSDElementDeclaration element = (XSDElementDeclaration) iter.next();
> >>> if (!isReferenced(element, schema))
> >>> {
> >>> System.out.println(" Element: <" + element.getName() + "> is a root
> >>>element.");
> >>> }
> >>> }
> >>>
> >>>------------------
> >>>
> >>>boolean isReferenced(XSDElementDeclaration element, XSDSchema schema)
> >>> {
> >>> int count = 0;
> >>>
> >>> // Determine how many references there are to this element
> >>> ArrayList list = (ArrayList) UsageCrossReferencer.find(element,
> >>>
> >>>
> >schema);
> >
> >
> >>> for (Iterator i = list.iterator(); i.hasNext();)
> >>> {
> >>> Setting setting = (Setting) i.next();
> >>> EObject obj = setting.getEObject();
> >>> if (obj != schema && obj != element)
> >>> count++;
> >>> }
> >>>
> >>> return count > 0;
> >>> }
> >>>
> >>>
> >>>Note I think this also counts references in types that might not
> >>>
> >>>
> >themselves
> >
> >
> >>>be referenced by elements. A more exact method might be to check for
> >>>element references when obj (above) is a particle. Does that sound
> >>>
> >>>
> >right?
> >
> >
> >>>Gary
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >
> >
> >
> >
Re: How to find "root" element in a schema. Check if an element is referenced [message #51403 is a reply to message #51347] Tue, 24 August 2004 11:35 Go to previous message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

This is a multi-part message in MIME format.
--------------080706020903080502040700
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Bertrand,

In general, it is a map from Map<EObject,
Collection<EStructuralFeature.Setting>>, so the items in the list are of
type EStructuralFeature.Setting.


Bertrand N. wrote:

>I Ed ,
>
>
>
>
>>Ed Merks wrote:
>>
>>
>
>
>
>
>
>>Gary,
>>
>>
>
>
>
>>You should probably use findAll(xsdSchema.getElementDeclarations(),
>>xsdSchema) to find the usages of all the elements at once. The result
>>is a map from element to a Collection of Settings, i.e., the Collection
>>for a find of a single element.
>>
>>
>
>I don' t really understand what this map contain .
>is that something like this : map("elementDeclarations","ArrayList")
>please correct me if i' am wrong :
> - the Key are all the Element "ElementDeclarations" retrieve
>"directly"
> from the Schema : sxdSchema.getElementDeclarations().
> - the value is an "ArrayList" : what is the contain of this
>"ArrayList" ?
>
>is it possible that the map something else than ArrayList
>
>
>
>
>>This way the whole schema is only
>>walked once.
>>
>>
>
>
>
>
>>Gary J wrote:
>>
>>
>
>
>
>>>I have one more problem which is more related to performance. I have a
>>>large schema with 15000+ lines of element declarations. When I search for
>>>the root elements it takes an extremely long time.
>>>
>>>I have looked at the code for XSDUtil.UsageCrossReferencer.find() and it
>>>seems that a new UsageCrossReferencer(schema) Collection is created for
>>>every find().
>>>
>>>Is there a way to speed this up by building the UsageCrossReferencer once
>>>and re-using it for subsequent find()'s ?
>>>
>>>UsageCrossReferencer is protected so I can not create an instance of it like
>>>this:
>>>
>>>UsageCrossReferencer xref = new UsageCrossReferencer(schema);
>>>
>>>Should I subclass UsageCrossReferencer to solve this problem or is there a
>>>better way?
>>>
>>>Thanks
>>>
>>>Gary
>>>
>>>
>>>
>>>"Ed Merks" <merks@ca.ibm.com> wrote in message
>>>news:cg36uk$l8k$1@eclipse.org...
>>>
>>>
>>>
>>>
>>>>Gary,
>>>>
>>>>Yes this looks reasonable. I think you are right that an element must
>>>>be referenced from a particle in order to be in a content model of
>>>>something. The two cases you filtered out (I think) are for the schema
>>>>referencing the element in the getElementDeclarations, and the element
>>>>referencing itself in the getResolvedElementDeclaration. Note that an
>>>>element may reference another element with
>>>>getSubstitutionGroupAffiliation. Looking at the feature of the Setting
>>>>will help tell you how the object is referencing the element. Note that
>>>>something like XSDPackage.eINSTANCE.getXSDParticle_Term() will give you
>>>>access to the feature for comparing against the feature you see in the
>>>>Setting.
>>>>
>>>>
>>>>Gary J wrote:
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>>Thanks Ed,
>>>>>
>>>>>Once I used the schema to compare against all seems to work. For anyone
>>>>>else who's interested, here's what I did. Is this a reasonable approach?
>>>>>
>>>>>EList elements = schema.getSchema().getElementDeclarations();
>>>>>for (Iterator iter = elements.iterator(); iter.hasNext();)
>>>>> {
>>>>> XSDElementDeclaration element = (XSDElementDeclaration) iter.next();
>>>>> if (!isReferenced(element, schema))
>>>>> {
>>>>> System.out.println(" Element: <" + element.getName() + "> is a root
>>>>>element.");
>>>>> }
>>>>> }
>>>>>
>>>>>------------------
>>>>>
>>>>>boolean isReferenced(XSDElementDeclaration element, XSDSchema schema)
>>>>>{
>>>>>int count = 0;
>>>>>
>>>>>// Determine how many references there are to this element
>>>>>ArrayList list = (ArrayList) UsageCrossReferencer.find(element,
>>>>>
>>>>>
>>>>>
>>>>>
>>>schema);
>>>
>>>
>>>
>>>
>>>>>for (Iterator i = list.iterator(); i.hasNext();)
>>>>> {
>>>>> Setting setting = (Setting) i.next();
>>>>> EObject obj = setting.getEObject();
>>>>> if (obj != schema && obj != element)
>>>>> count++;
>>>>> }
>>>>>
>>>>>return count > 0;
>>>>>}
>>>>>
>>>>>
>>>>>Note I think this also counts references in types that might not
>>>>>
>>>>>
>>>>>
>>>>>
>>>themselves
>>>
>>>
>>>
>>>
>>>>>be referenced by elements. A more exact method might be to check for
>>>>>element references when obj (above) is a particle. Does that sound
>>>>>
>>>>>
>>>>>
>>>>>
>>>right?
>>>
>>>
>>>
>>>
>>>>>Gary
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>
>>>
>>>
>>>
>
>
>
>


--------------080706020903080502040700
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Bertrand,<br>
<br>
In general, it is a map from Map&lt;EObject,
Collection&lt;EStructuralFeature.Setting&gt;&gt; , so the items in the
list are of type EStructuralFeature.Setting.<br>
<br>
<br>
Bertrand N. wrote:
<blockquote cite="midcgf4na$m9e$1@eclipse.org" type="cite">
<pre wrap="">I Ed ,


</pre>
<blockquote type="cite">
<pre wrap="">Ed Merks wrote:
</pre>
</blockquote>
<pre wrap=""><!---->


</pre>
<blockquote type="cite">
<pre wrap="">Gary,
</pre>
</blockquote>
<pre wrap=""><!---->
</pre>
<blockquote type="cite">
<pre wrap="">You should probably use findAll(xsdSchema.getElementDeclarations(),
xsdSchema) to find the usages of all the elements at once. The result
is a map from element to a Collection of Settings, i.e., the Collection
for a find of a single element.
</pre>
</blockquote>
<pre wrap=""><!---->
I don' t really understand what this map contain .
is that something like this : map("elementDeclarations","ArrayList")
please correct me if i' am wrong :
- the Key are all the Element "ElementDeclarations" retrieve
"directly"
from the Schema : sxdSchema.getElementDeclarations().
- the value is an "ArrayList" : what is the contain of this
"ArrayList" ?

is it possible that the map something else than ArrayList


</pre>
<blockquote type="cite">
<pre wrap="">This way the whole schema is only
walked once.
</pre>
</blockquote>
<pre wrap=""><!---->

</pre>
<blockquote type="cite">
<pre wrap="">Gary J wrote:
</pre>
</blockquote>
<pre wrap=""><!---->
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">I have one more problem which is more related to performance. I have a
large schema with 15000+ lines of element declarations. When I search for
the root elements it takes an extremely long time.

I have looked at the code for XSDUtil.UsageCrossReferencer.find() and it
seems that a new UsageCrossReferencer(schema) Collection is created for
every find().

Is there a way to speed this up by building the UsageCrossReferencer once
and re-using it for subsequent find()'s ?

UsageCrossReferencer is protected so I can not create an instance of it like
this:

UsageCrossReferencer xref = new UsageCrossReferencer(schema);

Should I subclass UsageCrossReferencer to solve this problem or is there a
better way?

Thanks

Gary



"Ed Merks" <a class="moz-txt-link-rfc2396E" href="mailto:merks@ca.ibm.com">&lt;merks@ca.ibm.com&gt;</a> wrote in message
<a class="moz-txt-link-freetext" href="news:cg36uk$l8k$1@eclipse.org">news:cg36uk$l8k$1@eclipse.org</a>...


</pre>
<blockquote type="cite">
<pre wrap="">Gary,

Yes this looks reasonable. I think you are right that an element must
be referenced from a particle in order to be in a content model of
something. The two cases you filtered out (I think) are for the schema
referencing the element in the getElementDeclarations, and the element
referencing itself in the getResolvedElementDeclaration. Note that an
element may reference another element with
getSubstitutionGroupAffiliation. Looking at the feature of the Setting
will help tell you how the object is referencing the element. Note that
something like XSDPackage.eINSTANCE.getXSDParticle_Term() will give you
access to the feature for comparing against the feature you see in the
Setting.


Gary J wrote:



</pre>
<blockquote type="cite">
<pre wrap="">Thanks Ed,

Once I used the schema to compare against all seems to work. For anyone
else who's interested, here's what I did. Is this a reasonable approach?

EList elements = schema.getSchema().getElementDeclarations();
for (Iterator iter = elements.iterator(); iter.hasNext();)
{
XSDElementDeclaration element = (XSDElementDeclaration) iter.next();
if (!isReferenced(element, schema))
{
System.out.println(" Element: &lt;" + element.getName() + "&gt; is a root
element.");
}
}

------------------

boolean isReferenced(XSDElementDeclaration element, XSDSchema schema)
{
int count = 0;

// Determine how many references there are to this element
ArrayList list = (ArrayList) UsageCrossReferencer.find(element,


</pre>
</blockquote>
</blockquote>
<pre wrap="">schema);


</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">for (Iterator i = list.iterator(); i.hasNext();)
{
Setting setting = (Setting) i.next();
EObject obj = setting.getEObject();
if (obj != schema &amp;&amp; obj != element)
count++;
}

return count &gt; 0;
}


Note I think this also counts references in types that might not


</pre>
</blockquote>
</blockquote>
<pre wrap="">themselves


</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">be referenced by elements. A more exact method might be to check for
element references when obj (above) is a particle. Does that sound


</pre>
</blockquote>
</blockquote>
<pre wrap="">right?


</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">Gary






</pre>
</blockquote>
</blockquote>
<pre wrap="">


</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->

</pre>
</blockquote>
<br>
</body>
</html>

--------------080706020903080502040700--
Re: How to find "root" element in a schema. Check if an element is referenced [message #590383 is a reply to message #50579] Thu, 19 August 2004 10:26 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Gary,

This sounds reasonable. You can use
org.eclipse.xsd.util.XSDUtil.UsageCrossReferencer to find all
references. Note that getElementDeclarations returns all element
declarations, including imported ones.


Gary J wrote:

>Hi,
>
>I have a schema loaded into an XSDSchema model which consists of a lot of
>element definitions of which only one is the root element for my document.
>
>In this case all the elements are defined "globally" (sorry if that's the
>incorrect term) and then referenced in other element definitions. For
>example: <xs:element ref="title" /> where "title" is declared elsewhere.
>
>I understand that there need not be a concept of a root element since schema
>simply defines elements that can be present in a document. In this
>particular case the schema defines a single document and there really is a
>root element. The "root" element should be the only one which is not
>referred to by anything else. Does this sound resonable?
>
>I process the schema by fetching all the Element Declarations:
>
>EList elements = schema.getSchema().getElementDeclarations()
>
>and processing each one.
>
>for (Iterator iter = elements.iterator(); iter.hasNext(); )
> {
> XSDElementDeclaration element = (XSDElementDeclaration)iter.next();
>
> // Check if this is the root element
> boolean flag = isReferenced(element, schema);
> }
>
>Assuming that this is the correct approach how can I easily find out if a
>given element is referenced by another element in the schema? In other
>words I need an isReferenced() method.
>
>Does anyone have any ideas or am I so far off track it isn't funny?
>
>Thanks
>
>Gary
>
>
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to find "root" element in a schema. Check if an element is referenced [message #590417 is a reply to message #50637] Thu, 19 August 2004 18:00 Go to previous message
Gary J is currently offline Gary JFriend
Messages: 61
Registered: July 2009
Member
Thanks Ed,

I tried it on a simple schema and got back a collection in both cases where
the element was referenced and where it was not.

Here's what I did:

EList elements = schema.getSchema().getElementDeclarations();
for (Iterator iter = elements.iterator(); iter.hasNext();)
{
XSDElementDeclaration element = (XSDElementDeclaration)iter.next();

// Test if element referenced
ArrayList list = (ArrayList)UsageCrossReferencer.find(element, elements);
}

The schema looks like this: (its the standard po example - file7)

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="PurchaseOrderType">
...
<xsd:element minOccurs="0" ref="comment"></xsd:element>
...
</xsd:complexType>
<xsd:element name="purchaseOrder" type="PurchaseOrderType"></xsd:element>
<xsd:element name="comment" type="xsd:string"></xsd:element>
</xsd:schema>

I get back two elements and check each one for referenced. Sorry if I'm
totally stupid. How do I determine that the element comment is referenced
by the element purchaseOrder? I've looked everywhere in 'list' in debug but
can not find anything.

Thanks
Re: How to find "root" element in a schema. Check if an element is referenced [message #590428 is a reply to message #50694] Thu, 19 August 2004 19:09 Go to previous message
user is currently offline userFriend
Messages: 296
Registered: July 2009
Senior Member
How do I determine that the element comment is referenced by the element
purchaseOrder? look at the schema.
1. the element with name="purchaseOrder" is of type="PurchaseOrderType"
2. xsd:complexType name="PurchaseOrderType" contains an element with
ref="comment", a reference to the element comment.

norwood sisson

Gary J wrote:
> Thanks Ed,
>
> I tried it on a simple schema and got back a collection in both cases where
> the element was referenced and where it was not.
>
> Here's what I did:
>
> EList elements = schema.getSchema().getElementDeclarations();
> for (Iterator iter = elements.iterator(); iter.hasNext();)
> {
> XSDElementDeclaration element = (XSDElementDeclaration)iter.next();
>
> // Test if element referenced
> ArrayList list = (ArrayList)UsageCrossReferencer.find(element, elements);
> }
>
> The schema looks like this: (its the standard po example - file7)
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
> <xsd:complexType name="PurchaseOrderType">
> ...
> <xsd:element minOccurs="0" ref="comment"></xsd:element>
> ...
> </xsd:complexType>
> <xsd:element name="purchaseOrder" type="PurchaseOrderType"></xsd:element>
> <xsd:element name="comment" type="xsd:string"></xsd:element>
> </xsd:schema>
>
> I get back two elements and check each one for referenced. Sorry if I'm
> totally stupid. How do I determine that the element comment is referenced
> by the element purchaseOrder? I've looked everywhere in 'list' in debug but
> can not find anything.
>
> Thanks
Re: How to find "root" element in a schema. Check if an element is referenced [message #590457 is a reply to message #50637] Thu, 19 August 2004 19:12 Go to previous message
Gary J is currently offline Gary JFriend
Messages: 61
Registered: July 2009
Member
I think I answered part of my own question. I was only checking Element
declarations, not types. I'm now checking both and get back a larger list
for "comments".

Is there any documentation about what I should be seeing in these lists?

Here's my code:

EList elements = schema.getSchema().getElementDeclarations();
EList types = schema.getSchema().getTypeDefinitions();

for (Iterator iter = elements.iterator(); iter.hasNext();)
{
XSDElementDeclaration element = (XSDElementDeclaration)iter.next();
System.out.println(" Element: " + element.getName());

ArrayList elist = (ArrayList)UsageCrossReferencer.find(element,
elements);

// list contents of element references
for (Iterator i = elist.iterator(); i.hasNext();)
{
Object obj = i.next();
System.out.println(" Element ref: " + obj.getClass());
}

ArrayList tlist = (ArrayList)UsageCrossReferencer.find(element, types);

// list contents of type references
for (Iterator i = tlist.iterator(); i.hasNext();)
{
Object obj = i.next();
System.out.println(" Type ref: " + obj.getClass());
}

}

Here's what I get:

For the "comment" element I get:
Element: comment
Element ref: class org.eclipse.emf.ecore.impl.BasicEObjectImpl$2
Element ref: class org.eclipse.emf.ecore.util.EObjectEList

Type ref: class org.eclipse.emf.ecore.impl.BasicEObjectImpl$2
Type ref: class org.eclipse.emf.ecore.impl.BasicEObjectImpl$2
Type ref: class org.eclipse.emf.ecore.impl.BasicEObjectImpl$2
Type ref: class org.eclipse.emf.ecore.impl.BasicEObjectImpl$2

For the "purchaseOrder" element I get:
Element: purchaseOrder
Element ref: class org.eclipse.emf.ecore.impl.BasicEObjectImpl$2
Element ref: class org.eclipse.emf.ecore.util.EObjectEList

How do I decode all this?

Thanks

Gary

"Ed Merks" <merks@ca.ibm.com> wrote in message
news:cg1v5q$fu2$1@eclipse.org...
> Gary,
>
> This sounds reasonable. You can use
> org.eclipse.xsd.util.XSDUtil.UsageCrossReferencer to find all
> references. Note that getElementDeclarations returns all element
> declarations, including imported ones.
>
>
> Gary J wrote:
>
> >Hi,
> >
> >I have a schema loaded into an XSDSchema model which consists of a lot of
> >element definitions of which only one is the root element for my
document.
> >
> >In this case all the elements are defined "globally" (sorry if that's the
> >incorrect term) and then referenced in other element definitions. For
> >example: <xs:element ref="title" /> where "title" is declared
elsewhere.
> >
> >I understand that there need not be a concept of a root element since
schema
> >simply defines elements that can be present in a document. In this
> >particular case the schema defines a single document and there really is
a
> >root element. The "root" element should be the only one which is not
> >referred to by anything else. Does this sound resonable?
> >
> >I process the schema by fetching all the Element Declarations:
> >
> >EList elements = schema.getSchema().getElementDeclarations()
> >
> >and processing each one.
> >
> >for (Iterator iter = elements.iterator(); iter.hasNext(); )
> > {
> > XSDElementDeclaration element = (XSDElementDeclaration)iter.next();
> >
> > // Check if this is the root element
> > boolean flag = isReferenced(element, schema);
> > }
> >
> >Assuming that this is the correct approach how can I easily find out if a
> >given element is referenced by another element in the schema? In other
> >words I need an isReferenced() method.
> >
> >Does anyone have any ideas or am I so far off track it isn't funny?
> >
> >Thanks
> >
> >Gary
> >
> >
> >
> >
> >
Re: How to find "root" element in a schema. Check if an element is referenced [message #590478 is a reply to message #50722] Thu, 19 August 2004 19:18 Go to previous message
Gary J is currently offline Gary JFriend
Messages: 61
Registered: July 2009
Member
Thanks, you are correct that it is all in the schema but I was talking about
the XML Infoset Model, not the .xsd text file.

In the Infoset model the schema is expressed in a model of java objects
which the user can query. How to perform the traversing and interpret the
results was my question.

<user@domain.invalid> wrote in message news:cg2tma$7fn$1@eclipse.org...
> How do I determine that the element comment is referenced by the element
> purchaseOrder? look at the schema.
> 1. the element with name="purchaseOrder" is of type="PurchaseOrderType"
> 2. xsd:complexType name="PurchaseOrderType" contains an element with
> ref="comment", a reference to the element comment.
>
> norwood sisson
>

<user@domain.invalid> wrote in message news:cg2tma$7fn$1@eclipse.org...
> How do I determine that the element comment is referenced by the element
> purchaseOrder? look at the schema.
> 1. the element with name="purchaseOrder" is of type="PurchaseOrderType"
> 2. xsd:complexType name="PurchaseOrderType" contains an element with
> ref="comment", a reference to the element comment.
>
> norwood sisson
>
> Gary J wrote:
> > Thanks Ed,
> >
> > I tried it on a simple schema and got back a collection in both cases
where
> > the element was referenced and where it was not.
> >
> > Here's what I did:
> >
> > EList elements = schema.getSchema().getElementDeclarations();
> > for (Iterator iter = elements.iterator(); iter.hasNext();)
> > {
> > XSDElementDeclaration element = (XSDElementDeclaration)iter.next();
> >
> > // Test if element referenced
> > ArrayList list = (ArrayList)UsageCrossReferencer.find(element,
elements);
> > }
> >
> > The schema looks like this: (its the standard po example - file7)
> >
> > <?xml version="1.0" encoding="UTF-8"?>
> > <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
> > <xsd:complexType name="PurchaseOrderType">
> > ...
> > <xsd:element minOccurs="0" ref="comment"></xsd:element>
> > ...
> > </xsd:complexType>
> > <xsd:element name="purchaseOrder"
type="PurchaseOrderType"></xsd:element>
> > <xsd:element name="comment" type="xsd:string"></xsd:element>
> > </xsd:schema>
> >
> > I get back two elements and check each one for referenced. Sorry if I'm
> > totally stupid. How do I determine that the element comment is
referenced
> > by the element purchaseOrder? I've looked everywhere in 'list' in debug
but
> > can not find anything.
> >
> > Thanks
Re: How to find "root" element in a schema. Check if an element is referenced [message #590495 is a reply to message #50777] Thu, 19 August 2004 19:55 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------090206070101090509000002
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Gary,

You should be doing the find against the whole resource set, the whole
resource, or the whole schema, not just against the list of elements or
the list of types. The objects in the list are of type
org.eclipse.emf.ecore.EStructuralFeature.Setting from which you can
determine the object doing the referencing as well as the feature of the
object that holds the reference. Only the base class in EMF
(EcoreUtil.UsageCrossReferencer) has javadoc...


Gary J wrote:

>I think I answered part of my own question. I was only checking Element
>declarations, not types. I'm now checking both and get back a larger list
>for "comments".
>
>Is there any documentation about what I should be seeing in these lists?
>
>Here's my code:
>
> EList elements = schema.getSchema().getElementDeclarations();
> EList types = schema.getSchema().getTypeDefinitions();
>
> for (Iterator iter = elements.iterator(); iter.hasNext();)
> {
> XSDElementDeclaration element = (XSDElementDeclaration)iter.next();
> System.out.println(" Element: " + element.getName());
>
> ArrayList elist = (ArrayList)UsageCrossReferencer.find(element,
>elements);
>
> // list contents of element references
> for (Iterator i = elist.iterator(); i.hasNext();)
> {
> Object obj = i.next();
> System.out.println(" Element ref: " + obj.getClass());
> }
>
> ArrayList tlist = (ArrayList)UsageCrossReferencer.find(element, types);
>
> // list contents of type references
> for (Iterator i = tlist.iterator(); i.hasNext();)
> {
> Object obj = i.next();
> System.out.println(" Type ref: " + obj.getClass());
> }
>
> }
>
>Here's what I get:
>
>For the "comment" element I get:
>Element: comment
>Element ref: class org.eclipse.emf.ecore.impl.BasicEObjectImpl$2
>Element ref: class org.eclipse.emf.ecore.util.EObjectEList
>
>Type ref: class org.eclipse.emf.ecore.impl.BasicEObjectImpl$2
>Type ref: class org.eclipse.emf.ecore.impl.BasicEObjectImpl$2
>Type ref: class org.eclipse.emf.ecore.impl.BasicEObjectImpl$2
>Type ref: class org.eclipse.emf.ecore.impl.BasicEObjectImpl$2
>
>For the "purchaseOrder" element I get:
>Element: purchaseOrder
>Element ref: class org.eclipse.emf.ecore.impl.BasicEObjectImpl$2
>Element ref: class org.eclipse.emf.ecore.util.EObjectEList
>
>How do I decode all this?
>
>Thanks
>
>Gary
>
>"Ed Merks" <merks@ca.ibm.com> wrote in message
>news:cg1v5q$fu2$1@eclipse.org...
>
>
>>Gary,
>>
>>This sounds reasonable. You can use
>>org.eclipse.xsd.util.XSDUtil.UsageCrossReferencer to find all
>>references. Note that getElementDeclarations returns all element
>>declarations, including imported ones.
>>
>>
>>Gary J wrote:
>>
>>
>>
>>>Hi,
>>>
>>>I have a schema loaded into an XSDSchema model which consists of a lot of
>>>element definitions of which only one is the root element for my
>>>
>>>
>document.
>
>
>>>In this case all the elements are defined "globally" (sorry if that's the
>>>incorrect term) and then referenced in other element definitions. For
>>>example: <xs:element ref="title" /> where "title" is declared
>>>
>>>
>elsewhere.
>
>
>>>I understand that there need not be a concept of a root element since
>>>
>>>
>schema
>
>
>>>simply defines elements that can be present in a document. In this
>>>particular case the schema defines a single document and there really is
>>>
>>>
>a
>
>
>>>root element. The "root" element should be the only one which is not
>>>referred to by anything else. Does this sound resonable?
>>>
>>>I process the schema by fetching all the Element Declarations:
>>>
>>>EList elements = schema.getSchema().getElementDeclarations()
>>>
>>>and processing each one.
>>>
>>>for (Iterator iter = elements.iterator(); iter.hasNext(); )
>>> {
>>> XSDElementDeclaration element = (XSDElementDeclaration)iter.next();
>>>
>>> // Check if this is the root element
>>> boolean flag = isReferenced(element, schema);
>>> }
>>>
>>>Assuming that this is the correct approach how can I easily find out if a
>>>given element is referenced by another element in the schema? In other
>>>words I need an isReferenced() method.
>>>
>>>Does anyone have any ideas or am I so far off track it isn't funny?
>>>
>>>Thanks
>>>
>>>Gary
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>
>
>
>


--------------090206070101090509000002
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Gary,<br>
<br>
You should be doing the find against the whole resource set, the whole
resource, or the whole schema, not just against the list of elements or
the list of types.&nbsp; The objects in the list are of type
org.eclipse.emf.ecore.EStructuralFeature.Setting from which you can
determine the object doing the referencing as well as the feature of
the object that holds the reference.&nbsp; Only the base class in EMF
(EcoreUtil.UsageCrossReferencer) has javadoc...<br>
<br>
<br>
Gary J wrote:<br>
<blockquote cite="midcg2tt0$7ps$1@eclipse.org" type="cite">
<pre wrap="">I think I answered part of my own question. I was only checking Element
declarations, not types. I'm now checking both and get back a larger list
for "comments".

Is there any documentation about what I should be seeing in these lists?

Here's my code:

EList elements = schema.getSchema().getElementDeclarations();
EList types = schema.getSchema().getTypeDefinitions();

for (Iterator iter = elements.iterator(); iter.hasNext();)
{
XSDElementDeclaration element = (XSDElementDeclaration)iter.next();
System.out.println(" Element: " + element.getName());

ArrayList elist = (ArrayList)UsageCrossReferencer.find(element,
elements);

// list contents of element references
for (Iterator i = elist.iterator(); i.hasNext();)
{
Object obj = i.next();
System.out.println(" Element ref: " + obj.getClass());
}

ArrayList tlist = (ArrayList)UsageCrossReferencer.find(element, types);

// list contents of type references
for (Iterator i = tlist.iterator(); i.hasNext();)
{
Object obj = i.next();
System.out.println(" Type ref: " + obj.getClass());
}

}

Here's what I get:

For the "comment" element I get:
Element: comment
Element ref: class org.eclipse.emf.ecore.impl.BasicEObjectImpl$2
Element ref: class org.eclipse.emf.ecore.util.EObjectEList

Type ref: class org.eclipse.emf.ecore.impl.BasicEObjectImpl$2
Type ref: class org.eclipse.emf.ecore.impl.BasicEObjectImpl$2
Type ref: class org.eclipse.emf.ecore.impl.BasicEObjectImpl$2
Type ref: class org.eclipse.emf.ecore.impl.BasicEObjectImpl$2

For the "purchaseOrder" element I get:
Element: purchaseOrder
Element ref: class org.eclipse.emf.ecore.impl.BasicEObjectImpl$2
Element ref: class org.eclipse.emf.ecore.util.EObjectEList

How do I decode all this?

Thanks

Gary

"Ed Merks" <a class="moz-txt-link-rfc2396E" href="mailto:merks@ca.ibm.com">&lt;merks@ca.ibm.com&gt;</a> wrote in message
<a class="moz-txt-link-freetext" href="news:cg1v5q$fu2$1@eclipse.org">news:cg1v5q$fu2$1@eclipse.org</a>...
</pre>
<blockquote type="cite">
<pre wrap="">Gary,

This sounds reasonable. You can use
org.eclipse.xsd.util.XSDUtil.UsageCrossReferencer to find all
references. Note that getElementDeclarations returns all element
declarations, including imported ones.


Gary J wrote:

</pre>
<blockquote type="cite">
<pre wrap="">Hi,

I have a schema loaded into an XSDSchema model which consists of a lot of
element definitions of which only one is the root element for my
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->document.
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">In this case all the elements are defined "globally" (sorry if that's the
incorrect term) and then referenced in other element definitions. For
example: &lt;xs:element ref="title" /&gt; where "title" is declared
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->elsewhere.
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">I understand that there need not be a concept of a root element since
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->schema
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">simply defines elements that can be present in a document. In this
particular case the schema defines a single document and there really is
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->a
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">root element. The "root" element should be the only one which is not
referred to by anything else. Does this sound resonable?

I process the schema by fetching all the Element Declarations:

EList elements = schema.getSchema().getElementDeclarations()

and processing each one.

for (Iterator iter = elements.iterator(); iter.hasNext(); )
{
XSDElementDeclaration element = (XSDElementDeclaration)iter.next();

// Check if this is the root element
boolean flag = isReferenced(element, schema);
}

Assuming that this is the correct approach how can I easily find out if a
given element is referenced by another element in the schema? In other
words I need an isReferenced() method.

Does anyone have any ideas or am I so far off track it isn't funny?

Thanks

Gary





</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->

</pre>
</blockquote>
<br>
</body>
</html>

--------------090206070101090509000002--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to find "root" element in a schema. Check if an element is referenced [message #590522 is a reply to message #50854] Thu, 19 August 2004 21:30 Go to previous message
Gary J is currently offline Gary JFriend
Messages: 61
Registered: July 2009
Member
Thanks Ed,

Once I used the schema to compare against all seems to work. For anyone
else who's interested, here's what I did. Is this a reasonable approach?

EList elements = schema.getSchema().getElementDeclarations();
for (Iterator iter = elements.iterator(); iter.hasNext();)
{
XSDElementDeclaration element = (XSDElementDeclaration) iter.next();
if (!isReferenced(element, schema))
{
System.out.println(" Element: <" + element.getName() + "> is a root
element.");
}
}

------------------

boolean isReferenced(XSDElementDeclaration element, XSDSchema schema)
{
int count = 0;

// Determine how many references there are to this element
ArrayList list = (ArrayList) UsageCrossReferencer.find(element, schema);
for (Iterator i = list.iterator(); i.hasNext();)
{
Setting setting = (Setting) i.next();
EObject obj = setting.getEObject();
if (obj != schema && obj != element)
count++;
}

return count > 0 ? false : true;
}


Note I think this also counts references in types that might not themselves
be referenced by elements. A more exact method might be to check for
element references when obj (above) is a particle. Does that sound right?

Gary
Re: How to find "root" element in a schema. Check if an element is referenced [message #590545 is a reply to message #50881] Thu, 19 August 2004 21:40 Go to previous message
Gary J is currently offline Gary JFriend
Messages: 61
Registered: July 2009
Member
minor correction.

return count > 0 ? false : true;

shoud be

return count > 0 ? true : false;



"Gary J" <gj@puredge.com> wrote in message news:cg360c$k1f$1@eclipse.org...
> Thanks Ed,
>
> Once I used the schema to compare against all seems to work. For anyone
> else who's interested, here's what I did. Is this a reasonable approach?
>
> EList elements = schema.getSchema().getElementDeclarations();
> for (Iterator iter = elements.iterator(); iter.hasNext();)
> {
> XSDElementDeclaration element = (XSDElementDeclaration) iter.next();
> if (!isReferenced(element, schema))
> {
> System.out.println(" Element: <" + element.getName() + "> is a root
> element.");
> }
> }
>
> ------------------
>
> boolean isReferenced(XSDElementDeclaration element, XSDSchema schema)
> {
> int count = 0;
>
> // Determine how many references there are to this element
> ArrayList list = (ArrayList) UsageCrossReferencer.find(element, schema);
> for (Iterator i = list.iterator(); i.hasNext();)
> {
> Setting setting = (Setting) i.next();
> EObject obj = setting.getEObject();
> if (obj != schema && obj != element)
> count++;
> }
>
> return count > 0 ? false : true;
> }
>
>
> Note I think this also counts references in types that might not
themselves
> be referenced by elements. A more exact method might be to check for
> element references when obj (above) is a particle. Does that sound right?
>
> Gary
>
>
Re: How to find "root" element in a schema. Check if an element is referenced [message #590564 is a reply to message #50881] Thu, 19 August 2004 21:45 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Gary,

Yes this looks reasonable. I think you are right that an element must
be referenced from a particle in order to be in a content model of
something. The two cases you filtered out (I think) are for the schema
referencing the element in the getElementDeclarations, and the element
referencing itself in the getResolvedElementDeclaration. Note that an
element may reference another element with
getSubstitutionGroupAffiliation. Looking at the feature of the Setting
will help tell you how the object is referencing the element. Note that
something like XSDPackage.eINSTANCE.getXSDParticle_Term() will give you
access to the feature for comparing against the feature you see in the
Setting.


Gary J wrote:

>Thanks Ed,
>
>Once I used the schema to compare against all seems to work. For anyone
>else who's interested, here's what I did. Is this a reasonable approach?
>
> EList elements = schema.getSchema().getElementDeclarations();
> for (Iterator iter = elements.iterator(); iter.hasNext();)
> {
> XSDElementDeclaration element = (XSDElementDeclaration) iter.next();
> if (!isReferenced(element, schema))
> {
> System.out.println(" Element: <" + element.getName() + "> is a root
>element.");
> }
> }
>
>------------------
>
> boolean isReferenced(XSDElementDeclaration element, XSDSchema schema)
> {
> int count = 0;
>
> // Determine how many references there are to this element
> ArrayList list = (ArrayList) UsageCrossReferencer.find(element, schema);
> for (Iterator i = list.iterator(); i.hasNext();)
> {
> Setting setting = (Setting) i.next();
> EObject obj = setting.getEObject();
> if (obj != schema && obj != element)
> count++;
> }
>
> return count > 0 ? false : true;
> }
>
>
>Note I think this also counts references in types that might not themselves
>be referenced by elements. A more exact method might be to check for
>element references when obj (above) is a particle. Does that sound right?
>
>Gary
>
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to find "root" element in a schema. Check if an element is referenced [message #590580 is a reply to message #50910] Thu, 19 August 2004 21:47 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------020506080505040006010506
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Gary,

This would be slightly more simple. ;-)

return count > 0;


Gary J wrote:

>minor correction.
>
>return count > 0 ? false : true;
>
>shoud be
>
>return count > 0 ? true : false;
>
>
>
>"Gary J" <gj@puredge.com> wrote in message news:cg360c$k1f$1@eclipse.org...
>
>
>>Thanks Ed,
>>
>>Once I used the schema to compare against all seems to work. For anyone
>>else who's interested, here's what I did. Is this a reasonable approach?
>>
>> EList elements = schema.getSchema().getElementDeclarations();
>> for (Iterator iter = elements.iterator(); iter.hasNext();)
>> {
>> XSDElementDeclaration element = (XSDElementDeclaration) iter.next();
>> if (!isReferenced(element, schema))
>> {
>> System.out.println(" Element: <" + element.getName() + "> is a root
>>element.");
>> }
>> }
>>
>>------------------
>>
>> boolean isReferenced(XSDElementDeclaration element, XSDSchema schema)
>> {
>> int count = 0;
>>
>> // Determine how many references there are to this element
>> ArrayList list = (ArrayList) UsageCrossReferencer.find(element, schema);
>> for (Iterator i = list.iterator(); i.hasNext();)
>> {
>> Setting setting = (Setting) i.next();
>> EObject obj = setting.getEObject();
>> if (obj != schema && obj != element)
>> count++;
>> }
>>
>> return count > 0 ? false : true;
>> }
>>
>>
>>Note I think this also counts references in types that might not
>>
>>
>themselves
>
>
>>be referenced by elements. A more exact method might be to check for
>>element references when obj (above) is a particle. Does that sound right?
>>
>>Gary
>>
>>
>>
>>
>
>
>
>


--------------020506080505040006010506
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Gary,<br>
<br>
This would be slightly more simple. ;-)<br>
<br>
<blockquote>&nbsp; return count &gt; 0;<br>
</blockquote>
<br>
Gary J wrote:<br>
<blockquote cite="midcg36j6$kqa$1@eclipse.org" type="cite">
<pre wrap="">minor correction.

return count &gt; 0 ? false : true;

shoud be

return count &gt; 0 ? true : false;



"Gary J" <a class="moz-txt-link-rfc2396E" href="mailto:gj@puredge.com">&lt;gj@puredge.com&gt;</a> wrote in message <a class="moz-txt-link-freetext" href="news:cg360c$k1f$1@eclipse.org">news:cg360c$k1f$1@eclipse.org</a>...
</pre>
<blockquote type="cite">
<pre wrap="">Thanks Ed,

Once I used the schema to compare against all seems to work. For anyone
else who's interested, here's what I did. Is this a reasonable approach?

EList elements = schema.getSchema().getElementDeclarations();
for (Iterator iter = elements.iterator(); iter.hasNext();)
{
XSDElementDeclaration element = (XSDElementDeclaration) iter.next();
if (!isReferenced(element, schema))
{
System.out.println(" Element: &lt;" + element.getName() + "&gt; is a root
element.");
}
}

------------------

boolean isReferenced(XSDElementDeclaration element, XSDSchema schema)
{
int count = 0;

// Determine how many references there are to this element
ArrayList list = (ArrayList) UsageCrossReferencer.find(element, schema);
for (Iterator i = list.iterator(); i.hasNext();)
{
Setting setting = (Setting) i.next();
EObject obj = setting.getEObject();
if (obj != schema &amp;&amp; obj != element)
count++;
}

return count &gt; 0 ? false : true;
}


Note I think this also counts references in types that might not
</pre>
</blockquote>
<pre wrap=""><!---->themselves
</pre>
<blockquote type="cite">
<pre wrap="">be referenced by elements. A more exact method might be to check for
element references when obj (above) is a particle. Does that sound right?

Gary


</pre>
</blockquote>
<pre wrap=""><!---->

</pre>
</blockquote>
<br>
</body>
</html>

--------------020506080505040006010506--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to find "root" element in a schema. Check if an element is referenced [message #590598 is a reply to message #50937] Thu, 19 August 2004 22:59 Go to previous message
Gary J is currently offline Gary JFriend
Messages: 61
Registered: July 2009
Member
I have one more problem which is more related to performance. I have a
large schema with 15000+ lines of element declarations. When I search for
the root elements it takes an extremely long time.

I have looked at the code for XSDUtil.UsageCrossReferencer.find() and it
seems that a new UsageCrossReferencer(schema) Collection is created for
every find().

Is there a way to speed this up by building the UsageCrossReferencer once
and re-using it for subsequent find()'s ?

UsageCrossReferencer is protected so I can not create an instance of it like
this:

UsageCrossReferencer xref = new UsageCrossReferencer(schema);

Should I subclass UsageCrossReferencer to solve this problem or is there a
better way?

Thanks

Gary



"Ed Merks" <merks@ca.ibm.com> wrote in message
news:cg36uk$l8k$1@eclipse.org...
> Gary,
>
> Yes this looks reasonable. I think you are right that an element must
> be referenced from a particle in order to be in a content model of
> something. The two cases you filtered out (I think) are for the schema
> referencing the element in the getElementDeclarations, and the element
> referencing itself in the getResolvedElementDeclaration. Note that an
> element may reference another element with
> getSubstitutionGroupAffiliation. Looking at the feature of the Setting
> will help tell you how the object is referencing the element. Note that
> something like XSDPackage.eINSTANCE.getXSDParticle_Term() will give you
> access to the feature for comparing against the feature you see in the
> Setting.
>
>
> Gary J wrote:
>
> >Thanks Ed,
> >
> >Once I used the schema to compare against all seems to work. For anyone
> >else who's interested, here's what I did. Is this a reasonable approach?
> >
> > EList elements = schema.getSchema().getElementDeclarations();
> > for (Iterator iter = elements.iterator(); iter.hasNext();)
> > {
> > XSDElementDeclaration element = (XSDElementDeclaration) iter.next();
> > if (!isReferenced(element, schema))
> > {
> > System.out.println(" Element: <" + element.getName() + "> is a root
> >element.");
> > }
> > }
> >
> >------------------
> >
> > boolean isReferenced(XSDElementDeclaration element, XSDSchema schema)
> > {
> > int count = 0;
> >
> > // Determine how many references there are to this element
> > ArrayList list = (ArrayList) UsageCrossReferencer.find(element,
schema);
> > for (Iterator i = list.iterator(); i.hasNext();)
> > {
> > Setting setting = (Setting) i.next();
> > EObject obj = setting.getEObject();
> > if (obj != schema && obj != element)
> > count++;
> > }
> >
> > return count > 0;
> > }
> >
> >
> >Note I think this also counts references in types that might not
themselves
> >be referenced by elements. A more exact method might be to check for
> >element references when obj (above) is a particle. Does that sound
right?
> >
> >Gary
> >
> >
> >
> >
Re: How to find "root" element in a schema. Check if an element is referenced [message #590622 is a reply to message #50992] Fri, 20 August 2004 00:28 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------030706010606050706060802
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Gary,

You should probably use findAll(xsdSchema.getElementDeclarations(),
xsdSchema) to find the usages of all the elements at once. The result
is a map from element to a Collection of Settings, i.e., the Collection
for a find of a single element. This way the whole schema is only
walked once.


Gary J wrote:

>I have one more problem which is more related to performance. I have a
>large schema with 15000+ lines of element declarations. When I search for
>the root elements it takes an extremely long time.
>
>I have looked at the code for XSDUtil.UsageCrossReferencer.find() and it
>seems that a new UsageCrossReferencer(schema) Collection is created for
>every find().
>
>Is there a way to speed this up by building the UsageCrossReferencer once
>and re-using it for subsequent find()'s ?
>
>UsageCrossReferencer is protected so I can not create an instance of it like
>this:
>
>UsageCrossReferencer xref = new UsageCrossReferencer(schema);
>
>Should I subclass UsageCrossReferencer to solve this problem or is there a
>better way?
>
>Thanks
>
>Gary
>
>
>
>"Ed Merks" <merks@ca.ibm.com> wrote in message
>news:cg36uk$l8k$1@eclipse.org...
>
>
>>Gary,
>>
>>Yes this looks reasonable. I think you are right that an element must
>>be referenced from a particle in order to be in a content model of
>>something. The two cases you filtered out (I think) are for the schema
>>referencing the element in the getElementDeclarations, and the element
>>referencing itself in the getResolvedElementDeclaration. Note that an
>>element may reference another element with
>>getSubstitutionGroupAffiliation. Looking at the feature of the Setting
>>will help tell you how the object is referencing the element. Note that
>>something like XSDPackage.eINSTANCE.getXSDParticle_Term() will give you
>>access to the feature for comparing against the feature you see in the
>>Setting.
>>
>>
>>Gary J wrote:
>>
>>
>>
>>>Thanks Ed,
>>>
>>>Once I used the schema to compare against all seems to work. For anyone
>>>else who's interested, here's what I did. Is this a reasonable approach?
>>>
>>>EList elements = schema.getSchema().getElementDeclarations();
>>> for (Iterator iter = elements.iterator(); iter.hasNext();)
>>> {
>>> XSDElementDeclaration element = (XSDElementDeclaration) iter.next();
>>> if (!isReferenced(element, schema))
>>> {
>>> System.out.println(" Element: <" + element.getName() + "> is a root
>>>element.");
>>> }
>>> }
>>>
>>>------------------
>>>
>>>boolean isReferenced(XSDElementDeclaration element, XSDSchema schema)
>>> {
>>> int count = 0;
>>>
>>> // Determine how many references there are to this element
>>> ArrayList list = (ArrayList) UsageCrossReferencer.find(element,
>>>
>>>
>schema);
>
>
>>> for (Iterator i = list.iterator(); i.hasNext();)
>>> {
>>> Setting setting = (Setting) i.next();
>>> EObject obj = setting.getEObject();
>>> if (obj != schema && obj != element)
>>> count++;
>>> }
>>>
>>> return count > 0;
>>> }
>>>
>>>
>>>Note I think this also counts references in types that might not
>>>
>>>
>themselves
>
>
>>>be referenced by elements. A more exact method might be to check for
>>>element references when obj (above) is a particle. Does that sound
>>>
>>>
>right?
>
>
>>>Gary
>>>
>>>
>>>
>>>
>>>
>>>
>
>
>
>


--------------030706010606050706060802
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Gary,<br>
<br>
You should&nbsp; probably use findAll(xsdSchema.getElementDeclarations(),
xsdSchema) to find the usages of all the elements at once.&nbsp; The result
is a map from element to a Collection of Settings, i.e., the Collection
for a find of a single element.&nbsp; This way the whole schema is only
walked once.<br>
<br>
<br>
Gary J wrote:<br>
<blockquote cite="midcg3b7e$pt3$1@eclipse.org" type="cite">
<pre wrap="">I have one more problem which is more related to performance. I have a
large schema with 15000+ lines of element declarations. When I search for
the root elements it takes an extremely long time.

I have looked at the code for XSDUtil.UsageCrossReferencer.find() and it
seems that a new UsageCrossReferencer(schema) Collection is created for
every find().

Is there a way to speed this up by building the UsageCrossReferencer once
and re-using it for subsequent find()'s ?

UsageCrossReferencer is protected so I can not create an instance of it like
this:

UsageCrossReferencer xref = new UsageCrossReferencer(schema);

Should I subclass UsageCrossReferencer to solve this problem or is there a
better way?

Thanks

Gary



"Ed Merks" <a class="moz-txt-link-rfc2396E" href="mailto:merks@ca.ibm.com">&lt;merks@ca.ibm.com&gt;</a> wrote in message
<a class="moz-txt-link-freetext" href="news:cg36uk$l8k$1@eclipse.org">news:cg36uk$l8k$1@eclipse.org</a>...
</pre>
<blockquote type="cite">
<pre wrap="">Gary,

Yes this looks reasonable. I think you are right that an element must
be referenced from a particle in order to be in a content model of
something. The two cases you filtered out (I think) are for the schema
referencing the element in the getElementDeclarations, and the element
referencing itself in the getResolvedElementDeclaration. Note that an
element may reference another element with
getSubstitutionGroupAffiliation. Looking at the feature of the Setting
will help tell you how the object is referencing the element. Note that
something like XSDPackage.eINSTANCE.getXSDParticle_Term() will give you
access to the feature for comparing against the feature you see in the
Setting.


Gary J wrote:

</pre>
<blockquote type="cite">
<pre wrap="">Thanks Ed,

Once I used the schema to compare against all seems to work. For anyone
else who's interested, here's what I did. Is this a reasonable approach?

EList elements = schema.getSchema().getElementDeclarations();
for (Iterator iter = elements.iterator(); iter.hasNext();)
{
XSDElementDeclaration element = (XSDElementDeclaration) iter.next();
if (!isReferenced(element, schema))
{
System.out.println(" Element: &lt;" + element.getName() + "&gt; is a root
element.");
}
}

------------------

boolean isReferenced(XSDElementDeclaration element, XSDSchema schema)
{
int count = 0;

// Determine how many references there are to this element
ArrayList list = (ArrayList) UsageCrossReferencer.find(element,
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->schema);
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap=""> for (Iterator i = list.iterator(); i.hasNext();)
{
Setting setting = (Setting) i.next();
EObject obj = setting.getEObject();
if (obj != schema &amp;&amp; obj != element)
count++;
}

return count &gt; 0;
}


Note I think this also counts references in types that might not
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->themselves
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">be referenced by elements. A more exact method might be to check for
element references when obj (above) is a particle. Does that sound
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->right?
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">Gary




</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->

</pre>
</blockquote>
<br>
</body>
</html>

--------------030706010606050706060802--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to find "root" element in a schema. Check if an element is referenced [message #590832 is a reply to message #51020] Tue, 24 August 2004 10:19 Go to previous message
Eclipse UserFriend
Originally posted by: gnoutsa.hotmail.com

I Ed ,


>Ed Merks wrote:



> Gary,

> You should probably use findAll(xsdSchema.getElementDeclarations(),
> xsdSchema) to find the usages of all the elements at once. The result
> is a map from element to a Collection of Settings, i.e., the Collection
> for a find of a single element.

I don' t really understand what this map contain .
is that something like this : map("elementDeclarations","ArrayList")
please correct me if i' am wrong :
- the Key are all the Element "ElementDeclarations" retrieve
"directly"
from the Schema : sxdSchema.getElementDeclarations().
- the value is an "ArrayList" : what is the contain of this
"ArrayList" ?

is it possible that the map something else than ArrayList


> This way the whole schema is only
> walked once.


> Gary J wrote:

> >I have one more problem which is more related to performance. I have a
> >large schema with 15000+ lines of element declarations. When I search for
> >the root elements it takes an extremely long time.
> >
> >I have looked at the code for XSDUtil.UsageCrossReferencer.find() and it
> >seems that a new UsageCrossReferencer(schema) Collection is created for
> >every find().
> >
> >Is there a way to speed this up by building the UsageCrossReferencer once
> >and re-using it for subsequent find()'s ?
> >
> >UsageCrossReferencer is protected so I can not create an instance of it like
> >this:
> >
> >UsageCrossReferencer xref = new UsageCrossReferencer(schema);
> >
> >Should I subclass UsageCrossReferencer to solve this problem or is there a
> >better way?
> >
> >Thanks
> >
> >Gary
> >
> >
> >
> >"Ed Merks" <merks@ca.ibm.com> wrote in message
> >news:cg36uk$l8k$1@eclipse.org...
> >
> >
> >>Gary,
> >>
> >>Yes this looks reasonable. I think you are right that an element must
> >>be referenced from a particle in order to be in a content model of
> >>something. The two cases you filtered out (I think) are for the schema
> >>referencing the element in the getElementDeclarations, and the element
> >>referencing itself in the getResolvedElementDeclaration. Note that an
> >>element may reference another element with
> >>getSubstitutionGroupAffiliation. Looking at the feature of the Setting
> >>will help tell you how the object is referencing the element. Note that
> >>something like XSDPackage.eINSTANCE.getXSDParticle_Term() will give you
> >>access to the feature for comparing against the feature you see in the
> >>Setting.
> >>
> >>
> >>Gary J wrote:
> >>
> >>
> >>
> >>>Thanks Ed,
> >>>
> >>>Once I used the schema to compare against all seems to work. For anyone
> >>>else who's interested, here's what I did. Is this a reasonable approach?
> >>>
> >>>EList elements = schema.getSchema().getElementDeclarations();
> >>> for (Iterator iter = elements.iterator(); iter.hasNext();)
> >>> {
> >>> XSDElementDeclaration element = (XSDElementDeclaration) iter.next();
> >>> if (!isReferenced(element, schema))
> >>> {
> >>> System.out.println(" Element: <" + element.getName() + "> is a root
> >>>element.");
> >>> }
> >>> }
> >>>
> >>>------------------
> >>>
> >>>boolean isReferenced(XSDElementDeclaration element, XSDSchema schema)
> >>> {
> >>> int count = 0;
> >>>
> >>> // Determine how many references there are to this element
> >>> ArrayList list = (ArrayList) UsageCrossReferencer.find(element,
> >>>
> >>>
> >schema);
> >
> >
> >>> for (Iterator i = list.iterator(); i.hasNext();)
> >>> {
> >>> Setting setting = (Setting) i.next();
> >>> EObject obj = setting.getEObject();
> >>> if (obj != schema && obj != element)
> >>> count++;
> >>> }
> >>>
> >>> return count > 0;
> >>> }
> >>>
> >>>
> >>>Note I think this also counts references in types that might not
> >>>
> >>>
> >themselves
> >
> >
> >>>be referenced by elements. A more exact method might be to check for
> >>>element references when obj (above) is a particle. Does that sound
> >>>
> >>>
> >right?
> >
> >
> >>>Gary
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >
> >
> >
> >
Re: How to find "root" element in a schema. Check if an element is referenced [message #590877 is a reply to message #51347] Tue, 24 August 2004 11:35 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------080706020903080502040700
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Bertrand,

In general, it is a map from Map<EObject,
Collection<EStructuralFeature.Setting>>, so the items in the list are of
type EStructuralFeature.Setting.


Bertrand N. wrote:

>I Ed ,
>
>
>
>
>>Ed Merks wrote:
>>
>>
>
>
>
>
>
>>Gary,
>>
>>
>
>
>
>>You should probably use findAll(xsdSchema.getElementDeclarations(),
>>xsdSchema) to find the usages of all the elements at once. The result
>>is a map from element to a Collection of Settings, i.e., the Collection
>>for a find of a single element.
>>
>>
>
>I don' t really understand what this map contain .
>is that something like this : map("elementDeclarations","ArrayList")
>please correct me if i' am wrong :
> - the Key are all the Element "ElementDeclarations" retrieve
>"directly"
> from the Schema : sxdSchema.getElementDeclarations().
> - the value is an "ArrayList" : what is the contain of this
>"ArrayList" ?
>
>is it possible that the map something else than ArrayList
>
>
>
>
>>This way the whole schema is only
>>walked once.
>>
>>
>
>
>
>
>>Gary J wrote:
>>
>>
>
>
>
>>>I have one more problem which is more related to performance. I have a
>>>large schema with 15000+ lines of element declarations. When I search for
>>>the root elements it takes an extremely long time.
>>>
>>>I have looked at the code for XSDUtil.UsageCrossReferencer.find() and it
>>>seems that a new UsageCrossReferencer(schema) Collection is created for
>>>every find().
>>>
>>>Is there a way to speed this up by building the UsageCrossReferencer once
>>>and re-using it for subsequent find()'s ?
>>>
>>>UsageCrossReferencer is protected so I can not create an instance of it like
>>>this:
>>>
>>>UsageCrossReferencer xref = new UsageCrossReferencer(schema);
>>>
>>>Should I subclass UsageCrossReferencer to solve this problem or is there a
>>>better way?
>>>
>>>Thanks
>>>
>>>Gary
>>>
>>>
>>>
>>>"Ed Merks" <merks@ca.ibm.com> wrote in message
>>>news:cg36uk$l8k$1@eclipse.org...
>>>
>>>
>>>
>>>
>>>>Gary,
>>>>
>>>>Yes this looks reasonable. I think you are right that an element must
>>>>be referenced from a particle in order to be in a content model of
>>>>something. The two cases you filtered out (I think) are for the schema
>>>>referencing the element in the getElementDeclarations, and the element
>>>>referencing itself in the getResolvedElementDeclaration. Note that an
>>>>element may reference another element with
>>>>getSubstitutionGroupAffiliation. Looking at the feature of the Setting
>>>>will help tell you how the object is referencing the element. Note that
>>>>something like XSDPackage.eINSTANCE.getXSDParticle_Term() will give you
>>>>access to the feature for comparing against the feature you see in the
>>>>Setting.
>>>>
>>>>
>>>>Gary J wrote:
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>>Thanks Ed,
>>>>>
>>>>>Once I used the schema to compare against all seems to work. For anyone
>>>>>else who's interested, here's what I did. Is this a reasonable approach?
>>>>>
>>>>>EList elements = schema.getSchema().getElementDeclarations();
>>>>>for (Iterator iter = elements.iterator(); iter.hasNext();)
>>>>> {
>>>>> XSDElementDeclaration element = (XSDElementDeclaration) iter.next();
>>>>> if (!isReferenced(element, schema))
>>>>> {
>>>>> System.out.println(" Element: <" + element.getName() + "> is a root
>>>>>element.");
>>>>> }
>>>>> }
>>>>>
>>>>>------------------
>>>>>
>>>>>boolean isReferenced(XSDElementDeclaration element, XSDSchema schema)
>>>>>{
>>>>>int count = 0;
>>>>>
>>>>>// Determine how many references there are to this element
>>>>>ArrayList list = (ArrayList) UsageCrossReferencer.find(element,
>>>>>
>>>>>
>>>>>
>>>>>
>>>schema);
>>>
>>>
>>>
>>>
>>>>>for (Iterator i = list.iterator(); i.hasNext();)
>>>>> {
>>>>> Setting setting = (Setting) i.next();
>>>>> EObject obj = setting.getEObject();
>>>>> if (obj != schema && obj != element)
>>>>> count++;
>>>>> }
>>>>>
>>>>>return count > 0;
>>>>>}
>>>>>
>>>>>
>>>>>Note I think this also counts references in types that might not
>>>>>
>>>>>
>>>>>
>>>>>
>>>themselves
>>>
>>>
>>>
>>>
>>>>>be referenced by elements. A more exact method might be to check for
>>>>>element references when obj (above) is a particle. Does that sound
>>>>>
>>>>>
>>>>>
>>>>>
>>>right?
>>>
>>>
>>>
>>>
>>>>>Gary
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>
>>>
>>>
>>>
>
>
>
>


--------------080706020903080502040700
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Bertrand,<br>
<br>
In general, it is a map from Map&lt;EObject,
Collection&lt;EStructuralFeature.Setting&gt;&gt; , so the items in the
list are of type EStructuralFeature.Setting.<br>
<br>
<br>
Bertrand N. wrote:
<blockquote cite="midcgf4na$m9e$1@eclipse.org" type="cite">
<pre wrap="">I Ed ,


</pre>
<blockquote type="cite">
<pre wrap="">Ed Merks wrote:
</pre>
</blockquote>
<pre wrap=""><!---->


</pre>
<blockquote type="cite">
<pre wrap="">Gary,
</pre>
</blockquote>
<pre wrap=""><!---->
</pre>
<blockquote type="cite">
<pre wrap="">You should probably use findAll(xsdSchema.getElementDeclarations(),
xsdSchema) to find the usages of all the elements at once. The result
is a map from element to a Collection of Settings, i.e., the Collection
for a find of a single element.
</pre>
</blockquote>
<pre wrap=""><!---->
I don' t really understand what this map contain .
is that something like this : map("elementDeclarations","ArrayList")
please correct me if i' am wrong :
- the Key are all the Element "ElementDeclarations" retrieve
"directly"
from the Schema : sxdSchema.getElementDeclarations().
- the value is an "ArrayList" : what is the contain of this
"ArrayList" ?

is it possible that the map something else than ArrayList


</pre>
<blockquote type="cite">
<pre wrap="">This way the whole schema is only
walked once.
</pre>
</blockquote>
<pre wrap=""><!---->

</pre>
<blockquote type="cite">
<pre wrap="">Gary J wrote:
</pre>
</blockquote>
<pre wrap=""><!---->
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">I have one more problem which is more related to performance. I have a
large schema with 15000+ lines of element declarations. When I search for
the root elements it takes an extremely long time.

I have looked at the code for XSDUtil.UsageCrossReferencer.find() and it
seems that a new UsageCrossReferencer(schema) Collection is created for
every find().

Is there a way to speed this up by building the UsageCrossReferencer once
and re-using it for subsequent find()'s ?

UsageCrossReferencer is protected so I can not create an instance of it like
this:

UsageCrossReferencer xref = new UsageCrossReferencer(schema);

Should I subclass UsageCrossReferencer to solve this problem or is there a
better way?

Thanks

Gary



"Ed Merks" <a class="moz-txt-link-rfc2396E" href="mailto:merks@ca.ibm.com">&lt;merks@ca.ibm.com&gt;</a> wrote in message
<a class="moz-txt-link-freetext" href="news:cg36uk$l8k$1@eclipse.org">news:cg36uk$l8k$1@eclipse.org</a>...


</pre>
<blockquote type="cite">
<pre wrap="">Gary,

Yes this looks reasonable. I think you are right that an element must
be referenced from a particle in order to be in a content model of
something. The two cases you filtered out (I think) are for the schema
referencing the element in the getElementDeclarations, and the element
referencing itself in the getResolvedElementDeclaration. Note that an
element may reference another element with
getSubstitutionGroupAffiliation. Looking at the feature of the Setting
will help tell you how the object is referencing the element. Note that
something like XSDPackage.eINSTANCE.getXSDParticle_Term() will give you
access to the feature for comparing against the feature you see in the
Setting.


Gary J wrote:



</pre>
<blockquote type="cite">
<pre wrap="">Thanks Ed,

Once I used the schema to compare against all seems to work. For anyone
else who's interested, here's what I did. Is this a reasonable approach?

EList elements = schema.getSchema().getElementDeclarations();
for (Iterator iter = elements.iterator(); iter.hasNext();)
{
XSDElementDeclaration element = (XSDElementDeclaration) iter.next();
if (!isReferenced(element, schema))
{
System.out.println(" Element: &lt;" + element.getName() + "&gt; is a root
element.");
}
}

------------------

boolean isReferenced(XSDElementDeclaration element, XSDSchema schema)
{
int count = 0;

// Determine how many references there are to this element
ArrayList list = (ArrayList) UsageCrossReferencer.find(element,


</pre>
</blockquote>
</blockquote>
<pre wrap="">schema);


</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">for (Iterator i = list.iterator(); i.hasNext();)
{
Setting setting = (Setting) i.next();
EObject obj = setting.getEObject();
if (obj != schema &amp;&amp; obj != element)
count++;
}

return count &gt; 0;
}


Note I think this also counts references in types that might not


</pre>
</blockquote>
</blockquote>
<pre wrap="">themselves


</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">be referenced by elements. A more exact method might be to check for
element references when obj (above) is a particle. Does that sound


</pre>
</blockquote>
</blockquote>
<pre wrap="">right?


</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">Gary






</pre>
</blockquote>
</blockquote>
<pre wrap="">


</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->

</pre>
</blockquote>
<br>
</body>
</html>

--------------080706020903080502040700--


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:I need some XSDSchema to test my Application
Next Topic:JDOM & Eclipse
Goto Forum:
  


Current Time: Fri Mar 29 05:56:00 GMT 2024

Powered by FUDForum. Page generated in 0.05463 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top