You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Vincent Herrmann <vi...@free.fr> on 2009/12/13 15:09:07 UTC

Get attribute's ref from XSElementDeclaration

Hello,

 

I'm a French developer working on an eclipse plug-in. I'm trying to create
an editor which help user to create a XML file. 

To help user to create XML file my editor use the Content Assist from
eclipse. Completion proposal are given by a XSD file (or other).

 

I'm using xerces to parse this XSD file. I have a problem when I try to get
attribute from a XSElementDeclaration.

 

I'm using this code:

 

Private void attributes(XSElementDeclaration element){

                XSTypeDefinition type = element.getTypeDefinition();

XSObjectList attrs = ((XSComplexTypeDefinition)type).getAttributeUses();

For(int i = 0; I < attrs.getLength(); i++){

                XSAttributeUse attrUse = (XSAttributeUse)attrs.item(i);

XSAttributeDeclaration attr = attrUse.getAttrDeclaration() ;

 

System.out.println(attr.getName) ;

}

}

 

This code works but not exactly like I want. He prints:

Lang

Herf

Label

Tittle

.

 

I want print this : 

 

Ns3:Lang

Ns3:herf

Ns3:label

Ns3 :tittle

.

 

My XML Schema is like this :

 

<xs:attributeGroup name="att.xlink.attribute.label">

    <xs:attribute ref="ns3:label"/>

  </xs:attributeGroup>

  <xs:attributeGroup name="att.xlink.attribute.href">

    <xs:attribute ref="ns3:href"/>

  </xs:attributeGroup>

  <xs:attributeGroup name="att.xlink.attribute.type">

    <xs:attribute ref="ns3:type"/>

  </xs:attributeGroup>

  <xs:attributeGroup name="att.xlink.attribute.title">

    <xs:attribute ref="ns3:title"/>

  </xs:attributeGroup>

 

And in file ns3.xsd :

 

<?xml version="1.0" encoding="UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
targetNamespace="http://www.w3.org/1999/xlink"
xmlns:ns1="http://www.w3.org/ns/smil"
xmlns:mlif="http://www.iso.org/ns/MLIF"
xmlns:ns2="http://www.tei-c.org/ns/1.0"
xmlns:ns3="http://www.w3.org/1999/xlink">

  <xs:import namespace="http://www.iso.org/ns/MLIF"
schemaLocation="MLIF.xsd"/>

  <xs:import namespace="http://www.tei-c.org/ns/1.0"
schemaLocation="ns2.xsd"/>

  <xs:import namespace="http://www.w3.org/XML/1998/namespace"
schemaLocation="xml.xsd"/>

  <xs:import namespace="http://www.w3.org/ns/smil"
schemaLocation="ns1.xsd"/>

  <xs:attribute name="label"/>

  <xs:attribute name="href"/>

  <xs:attribute name="type"/>

  <xs:attribute name="title"/>

  <xs:attribute name="from"/>

  <xs:attribute name="to"/>

</xs:schema>

 

My code print attribute's name but I want attribute's ref. How must I do to
get it? I tried but I didn't find.

Sorry for my poor English :/

 

Regards,

Vincent.

 

 

 

 


Re: Get attribute's ref from XSElementDeclaration

Posted by Michael Glavassevich <mr...@apache.org>.
On Sun, 13 Dec 2009, Michael Ludwig wrote:

> Vincent Herrmann schrieb am 13.12.2009 um 15:09:07 (+0100):
>
>> XSAttributeDeclaration attr = attrUse.getAttrDeclaration() ;
>> System.out.println(attr.getName) ;
>
>> My code print attribute's name but I want attribute's ref. How must I
>> do to get it?
>
> org.apache.xerces.xs.XSAttributeDeclaration#getName - inherited from
> org.apache.xerces.xs.XSObject#getName - which is defined as:
>
>  The name of type NCName, as defined in XML Namespaces [...]
>
> An NCName is a non-colonized name, so it is only the local part, without
> the namespace. What you want is the so-called QName, the qualified name.
> There is no method to get the QName, which probably makes sense. Beware
> that QNames are always dependent on the in-scope namespaces, so they
> cannot always simply be extracted and transplanted.

Xerces' XML Schema API very closely models the schema components defined 
by the schema specification. The prefixes which were part of the schema 
documents that composed it are not part of this model and are not made 
available through the API.

> Take a look at the following two methods, one of them might offer what
> you want:
>
> org.apache.xerces.xs.XSAttributeDeclaration#getNamespace
> org.apache.xerces.xs.XSAttributeDeclaration#getNamespaceItem
>
> -- 
> Michael Ludwig
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org

---------------------------
Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: Get attribute's ref from XSElementDeclaration

Posted by Michael Ludwig <mi...@gmx.de>.
Vincent Herrmann schrieb am 13.12.2009 um 15:09:07 (+0100):

> XSAttributeDeclaration attr = attrUse.getAttrDeclaration() ;
> System.out.println(attr.getName) ;

> My code print attribute's name but I want attribute's ref. How must I
> do to get it?

org.apache.xerces.xs.XSAttributeDeclaration#getName - inherited from
org.apache.xerces.xs.XSObject#getName - which is defined as:

  The name of type NCName, as defined in XML Namespaces [...]

An NCName is a non-colonized name, so it is only the local part, without
the namespace. What you want is the so-called QName, the qualified name.
There is no method to get the QName, which probably makes sense. Beware
that QNames are always dependent on the in-scope namespaces, so they
cannot always simply be extracted and transplanted.

Take a look at the following two methods, one of them might offer what
you want:

org.apache.xerces.xs.XSAttributeDeclaration#getNamespace
org.apache.xerces.xs.XSAttributeDeclaration#getNamespaceItem

-- 
Michael Ludwig

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org