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

  • Home
  • SEARCH
  • 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 6688471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:24:28+00:00 2026-05-26T05:24:28+00:00

I am trying to parse cascaded types(not sure if this is the right term)

  • 0

I am trying to parse cascaded types(not sure if this is the right term) from xml files.

What I mean by cascaded types is that the attribute ntype of an xml element could be any of the following ones.

<ntype A> 
     <ntype A:A1>
     <ntype A:A2>
<ntype B>
     <ntype B:B1>
     <ntype B:B2>
...

This is similar to the layout specifications in the android xml files like android:layout_width,android:layout_height etc.,

The ntype decides the type of the xml file and based on that further processing of the data is done.

Currently the way I’m parsing this is by having all the ntypes in an enumerated datatype like this: (By removing the “:” from the ntype)


    public static enum NType {
           A,
           AA1,
           AA2,
           B,
           BB1,
           BB2,
           ...
    }

In the parser I do

NType nType = NType.valueof(attributes.getValue("ntype").replace(":","");

However, if a new ntype is added to the xml file and that type is not there in the enum the app crashes. I wanted to know if there is any better way of storing these cascaded types of data and how should I add a default behavior if the ntype doesn’t exist so that the app doesn’t crash.

Any help is appreciated.

PS: I am slightly less knowledgeable in theoretical computer science and I believe this is mostly a theoretical question as to which/what/how tools from programming language should be used.

  • 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-05-26T05:24:29+00:00Added an answer on May 26, 2026 at 5:24 am

    Not sure if it will work as your question is a little abstract and I don’t know what your ntypes are or what you need to do when processing the document. How about this…

    Rather than create your static enum, you could do a two-pass parsing operation and create a collection of some sort (perhaps a List<String> although other collections may be more suitable).

    In short, I’d run a first pass and use the collection’s contains(Object E) method to see if it already contains that ntype – if not then use the add(Object E) method to add it. Do this for the whole xml document.

    Second pass, process the document as you need to but (assuming you want an int value representing the ntype) use the collections indexOf(Object E) method.

    By parsing the document and compiling all of the ntypes on the first pass, you’ll be dynamically ensuring that you know all of them without risk of coming across an unknown ntype.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to parse some XML but apparently this is too much for a lazy
I trying to parse this string: $right = '34601)S(1,6)[2] - 34601)(11)[2] + 34601)(3)[2,4]'; with
I have an xml feed at this url Now im trying parse the content,
trying to parse this: <?xml version=1.0 encoding=UTF-8?> <directoryresponse xmlns=https://www.sisow.nl/Sisow/REST version=1.0.0> <directory> <issuer> <issuerid>01</issuerid> <issuername>ABN
Trying to parse out this xml file to get a list of Elements but
I am trying to parse XML using PHP DOM and then insert this data
I'm trying to parse XML files and I would like to provide a schema
I am trying to parse this date with SimpleDateFormat and it is not working:
Im trying to parse a Xml file from a URL, the xml is actually
I trying to parse xml from an inputstream using the sax parser. The inputstream

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.