XML Schema clean up tool

Are you missing a feature? Request it's implementation here.
nikolayo
Posts: 12

XML Schema clean up tool

Mon Apr 26, 2010 5:48 pm

I would like to suggest hereby that you develop a tool which removes unused types from an XML schema. One specific use case in which I need such tool badly is XML schema flattening. I do that a lot but resulting schema files turn out to be up to 5 times bigger than schemas flattened with other (than oXyten XML) tools. The reason for that is that oXygen flattening tool crams into generated flattened schema all types from all included schemas regardless of whether the types are really used or not in the generated schema. A schema clean up tool could solve this problem and it could also be valuable general purpose tool too.

Regards
Nikolay
sorin_ristache
Posts: 4144

Re: XML Schema clean up tool

Tue Apr 27, 2010 11:11 am

Hello,

Thank you for your suggestion. We will consider implementing an XML Schema clean up tool in a future version of Oxygen.


Thank you,
Sorin
nikolayo
Posts: 12

Re: XML Schema clean up tool

Tue Apr 27, 2010 11:37 am

Thank you. I hope it happens in 11.X.
nikolayo
Posts: 12

Re: XML Schema clean up tool

Wed Sep 15, 2010 12:45 pm

Any news on the status of this?

Regards
Nikolay
adrian
Posts: 2459

Re: XML Schema clean up tool

Wed Sep 15, 2010 2:17 pm

Hello,

Right now, it is scheduled for 13.x, but this might change. I've increased its priority a notch.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
nikolayo
Posts: 12

Re: XML Schema clean up tool

Sat Sep 25, 2010 11:13 pm

I guess I will skip 12.x then:).
Thank you. Looking forward...

Regards
Nikolay
csalsa
Posts: 97

Re: XML Schema clean up tool

Wed Oct 06, 2010 12:04 pm

I would also find an XML Schema clean up tool useful. But I think used in a slightly different way to Nikolay

We currently have an in-house tool that takes for its input a master XML schema and a group of XML files. From this input, the tool generates a sub XML schema with only the schema types matched from the input XML files. We have options to include the complete XML schema type or, more often, remove the superfluous elements and attributes from each type not found in any of the input XML files.

The master XML file was generated from a model as the super set of our service messages and the sub XML schemas are used in per message schema validation.
adrian
Posts: 2459

Re: XML Schema clean up tool

Wed Oct 06, 2010 4:11 pm

@csalsa:
Thank you for the feedback.

I've added your comments to our issue tracking tool and your use case will be taken under consideration when this feature gets implemented.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
xchaotic
Posts: 7

Re: XML Schema clean up tool

Mon Jul 25, 2011 12:25 pm

I would use that feature too, it would, of course need to support imported modules etc.

for now I run the following XPath:
//xs:complexType[not(./@name = //xs:element/@type)]
(which coincidentally detects anonymous types too, which we don't want in our schemas due to design patterns)
nikolayo
Posts: 12

Re: XML Schema clean up tool

Sat Feb 16, 2013 3:29 pm

Any news on this feature?

Regards
Nikolay
ionela
Posts: 229

Re: XML Schema clean up tool

Mon Feb 18, 2013 6:46 pm

Hi Nikolay,

Currently, this feature is scheduled to be implemented in v15, but this is not fixed, so it could be pushed further back.

Regards,
Ionela
Ionela Istodor
oXygen XML Editor and Author Support
nikolayo
Posts: 12

Re: XML Schema clean up tool

Wed Feb 20, 2013 1:07 am

Oh, well... I am giving this up. It is taking way too long. :( :(

For the benefit of everybody interisted in the matter, I am including below
an xquery script which I am currently using for the purpose of cleaning up
flattened schemas.


Code: Select all

(:===========================================================================

    Copyright(©) 2013 Nikolay Ognyanov
   
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
   
        http://www.apache.org/licenses/LICENSE-2.0
   
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
   
=============================================================================

 clean_xsd.xq :
 
    An xquery script which removes unused types from an xml schema.
 
    Should be applied only to flattened schemas!

===========================================================================:)

xquery version "3.0";

(:=========================================================================:)
(: 3.0 is needed for namespace constructors. XML schemas generally need    :)
(: "xmlns=..." even though all elements are in the xs: namespace because   :)
(: everything referenced in schemas must have namespace including e.g.     :)
(: type names which only appear within strings.                            :)
(:=========================================================================:)

declare function local:unused-types(
    $target      as element()*,
    $types       as element()*,
    $unusedTypes as element()*
)
    as element()*
{
    let
    $newTarget       := $target except $unusedTypes,
    $moreUnusedTypes := $types[
        not(
            (./@name = $newTarget/@type                  )
            or
            (./@name = $newTarget//xs:element/@type      )
            or
            (./@name = $newTarget//xs:attribute/@type    )
            or
            (./@name = $newTarget//xs:restriction/@base  )
            or
            (./@name = $newTarget//xs:extension/@base    )
            or
            (./@name = $newTarget//xs:list/@itemType     )
            or
            (./@name = $newTarget//xs:attributeGroup/@ref)
            or
            (
             some $mt in $newTarget//xs:union/@memberTypes
                satisfies contains(string($mt), string(./@name))
            )
        )
    ],
    $newUnusedTypes := $moreUnusedTypes except $unusedTypes
    return
    if(empty($newUnusedTypes))
    then
        $unusedTypes
    else
        local:unused-types($newTarget, $types, $moreUnusedTypes)
};

(:=========================================================================:)

declare function local:remove-unused-types(
    $target          as node()*,
    $blackList       as element()*,
    $skipAnnotations as xs:boolean

    as node()*
{   
    for $node in $target
    return
        if ($node instance of document-node())
        then
            document {
                local:remove-unused-types(
                    $node/node(), $blackList, $skipAnnotations)
            }
        else if ($node instance of element())
        then
            if(some $n in $blackList satisfies $n is $node)
            then
                ()
            else
                if(string(node-name($node)) = "xs:annotation"
                    and $skipAnnotations)
                then
                    ()
                else
                   element { node-name($node)} {
                        $node/@*,
                        if($node/.. instance of document-node())
                        then
                            in-scope-prefixes($node)!
                                namespace{.}
                                {namespace-uri-for-prefix(.,$node)}
                        else
                            (),
                        local:remove-unused-types(
                            $node/node(), $blackList, $skipAnnotations)
                    }
       else
            $node
} ;

(:=========================================================================:)

declare function local:clean-xsd(
    $xsd             as document-node(),
    $skipAnnotations as xs:boolean
)
    as document-node()
{
    let
        $topTypes :=
            $xsd/xs:schema/xs:attributeGroup |
            $xsd/xs:schema/xs:simpleType     |
            $xsd/xs:schema/xs:complexType,
        $unusedTypes :=
            local:unused-types($xsd/xs:schema/*, $topTypes, ())
    return
        local:remove-unused-types($xsd, $unusedTypes, $skipAnnotations)
};

(:=========================================================================:)

local:clean-xsd(/, false())

(:=========================================================================:)
RampantBadger
Posts: 2

Re: XML Schema clean up tool

Wed Mar 04, 2015 2:22 pm

any news on this as trialling oxygen developer at the moment in v16.1 and this is an important feature for me
RampantBadger
Posts: 2

Re: XML Schema clean up tool

Wed Mar 04, 2015 2:39 pm

unfortunately the xml query script supplied here removes some of my used entries as well as unused ones
adrian
Posts: 2459

Re: XML Schema clean up tool

Wed Mar 04, 2015 6:32 pm

Hi,

@RampantBadger: I'm afraid that the status has not changed for this feature request. It's still pending and remains to be scheduled.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Return to “Feature Request”

Who is online

Users browsing this forum: No registered users and 1 guest