global element to local

This should cover W3C XML Schema, Relax NG and DTD related problems.
gjledger2k
Posts: 16
Location: Chicago

global element to local

Mon Jan 17, 2011 2:30 am

Hello,
I have a schema that has a global element. I need to make it a local element. There's no "Unextract Global Element". How do I do this?

Thanks.

Greg
sorin_ristache
Posts: 4144

Re: global element to local

Mon Jan 17, 2011 1:25 pm

Hello,

In the current version there is no automatic refactoring action for that. We will consider adding such an action in a future version.

In the current version, if it is a W3C XML Schema, a RELAX NG schema or a NVDL one you can achieve that by drag and drop in the schema diagram (the Design editing mode), otherwise you should edit the content of the schema file in the Text editing mode.


Regards,
Sorin
gjledger2k
Posts: 16
Location: Chicago

Re: global element to local

Thu Jan 20, 2011 6:03 am

Thank you so much Sorin for all your help. I'm new to xsd's. I have to write a schema where there is an element called TITLE that is used throughout, and therefore should be global. There is one element where TITLE is a child and can have only 3 values (enumerations). So I'm wondering if you can have a global element, yet have local attributes?

But the real question is now, I built a schema with all local elements, some of which would be better as globals because they have the same name. How do I take a local element, make it a global, and also apply its "globalness" to all the other like-named elements?

Thanks again.
sorin_ristache
Posts: 4144

Re: global element to local

Thu Jan 20, 2011 11:27 am

You should declare that element as a global element in the XML Schema and include it as local element in other definitions with a reference to the global one. For example:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="global">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="elem" type="xs:string" maxOccurs="3"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
 
  <xs:complexType name="type">
    <xs:sequence>
      <xs:element ref="global" minOccurs="1" maxOccurs="2"/>
    </xs:sequence>
    <xs:attribute name="attr" type="xs:string"/>
  </xs:complexType>
</xs:schema>



Please read about global elements and references to elements in an XML Schema tutorial.


Regards,
Sorin

Return to “XML Schemas”

Who is online

Users browsing this forum: No registered users and 0 guests