Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8198583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:58:53+00:00 2026-06-07T05:58:53+00:00

how to get max depth of a xsd using xsom. For e.g: total number

  • 0

how to get max depth of a xsd using xsom.

For e.g: total number of elements under each complex types of the xsd?

Also if as complex types is there under that complex types the number of element + attributes under that……using dom\xsom\jaxb

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
 <xs:element name="root" type="root">
    <xs:annotation>
        <xs:documentation>
            Comment describing your root element
        </xs:documentation>
    </xs:annotation>
 </xs:element>

 <xs:complexType name="root">
    <xs:sequence>
        <xs:element name="element_count" type="xs:string"></xs:element>
        <xs:element name="employee" type="employee" maxOccurs="unbounded" minOccurs="0"></xs:element>
    </xs:sequence>
 </xs:complexType>

 <xs:complexType name="employee">
    <xs:sequence>
        <xs:element name="name" type="xs:string"></xs:element>
        <xs:element name="ID" type="xs:string"></xs:element>
        <xs:element name="Addresses" type="addresses" maxOccurs="1" minOccurs="0"></xs:element>
    </xs:sequence>
 </xs:complexType>

 <xs:complexType name="addresses">
    <xs:sequence>
        <xs:element name="address" type="address" maxOccurs="unbounded" minOccurs="0"></xs:element>
    </xs:sequence>
 </xs:complexType>

 <xs:complexType name="address">
    <xs:sequence>
        <xs:element name="line1" type="xs:string"></xs:element>
        <xs:element name="line2" type="xs:string"></xs:element>
        <xs:element name="city" type="xs:string"></xs:element>
        <xs:element name="type" type="xs:string"></xs:element>
    </xs:sequence>
 </xs:complexType>
</xs:schema>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T05:58:54+00:00Added an answer on June 7, 2026 at 5:58 am

    I was actually just looking for this. I could not find anything in the API, so found a way with recursion yesterday. I am simply pasting my recursive way to read to the deepest and add them into a Hashmap.

    /*
     * Parses the xml schema string into a hashmap
     * note that hashmap has a form of a tree
     */
    public HashMap<String, Object> getXmlElements(InputStream xml) {
        //---
        XSOMParser parser = new XSOMParser();
        //---
        try{
            parser.parse(xml);
        } catch(Exception ex){
            logger.fatal("Could not parse the inputstream: " + ex);
        }
        //---
        XSSchemaSet schemaSet = null;
        try {
            schemaSet = parser.getResult();
        } catch (SAXException ex) {
            logger.fatal("Could not parse: " + ex);
        }
        //---
        HashMap<String, Object> hmReturned = new HashMap<String, Object>();
        HashMap<String, Object> hm = new HashMap<String, Object>();
        Iterator <XSElementDecl> itre = schemaSet.iterateElementDecls();
        //---
        while(itre.hasNext()) {
            XSElementDecl xse = (XSElementDecl) itre.next();
            hmReturned.put(xse.getName(), hm);
            XSComplexType xscomp = xse.getType().asComplexType();
            if (xscomp != null) {
                XSContentType xscont = xscomp.getContentType();
                XSParticle particle = xscont.asParticle();
                getElementsRecursively(hm,  particle);
            }
        } 
        //---
        return hmReturned;
    }
    
    /*
     * recursive helper method of getXmlElements
     * note that since we don't know the "deepness" of the
     * schema a recursive way of implementation was necessary
     */
    private void getElementsRecursively(HashMap<String, Object> hm, XSParticle xsp) {
         if(xsp != null){
             XSTerm term = xsp.getTerm();
             if(term.isElementDecl()) {
                 XSComplexType xscmp =  (term.asElementDecl()).getType().asComplexType();
                 //---
                 if (xscmp == null){
                     if(xsp.getMinOccurs() == 0)
                         hm.put(term.asElementDecl().getName(), "|");
                     else
                         hm.put(term.asElementDecl().getName(), "=");
                 } else{
                     XSContentType xscont = xscmp.getContentType();
                     XSParticle particle = xscont.asParticle();
                     HashMap<String, Object> newHm = new HashMap<String, Object>();
                     getElementsRecursively(newHm, particle);
                     hm.put(term.asElementDecl().getName(), newHm);
                 }
                 //---
             } else if(term.isModelGroup()){
                 XSModelGroup model = term.asModelGroup();
                 XSParticle[] parr = model.getChildren();
                 for(XSParticle partemp : parr ){
                   getElementsRecursively(hm, partemp);
                 }
             }
         }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wonder if there is better way to get max from column c1 and
I'm using this script but I would like to specify a max depth to
I want to get max and min values with other column's values in ms
How can I get the max value of a DropDownList values in ASP.NET with
Need your help to get the max of CAP_PRICE based on certain criteria in
I have a clumsy way to get the max length of a column in
is it possible to get the current max-value of a column, only knowing tableID
How to get text: Text example max from: <td valign=top align=left> <a href=/server?tree=xabaf class=normal>
I have to get the database with the max space free in a exchange
I am trying to get the sum(comprate) for only max(effdt) having max(id) from the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.