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 8295397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:34:18+00:00 2026-06-08T14:34:18+00:00

I am currently trying to write a simple parser for some XMI files (Generated

  • 0

I am currently trying to write a simple parser for some XMI files (Generated from a UML diagram) but I am encountering some problems when I try to extract the target xmi.idref from this code snippet (I want to retrieve connected elements to a given activity, I have successfully retrieved all the incoming/outgoing edges) :

<UML2:ActivityEdge xmi.id = 'I6bf577d1m1387a6c0ea1mm7dcb' visibility = 'public' is Specification = 'false'>
    <UML2:ActivityEdge.target>
        <UML2:CallAction xmi.idref = 'I6bf577d1m1387a6c0ea1mm7dda'/>
    </UML2:ActivityEdge.target>

My problem is that when I try to extract the UML2:CallAction, my program does not detect it as an element node but rather as a text node, which is by the way empty. Here is a sample of what I do :

Element edge = searchById(doc,"UML2:ActivityEdge",id);
        Element group = (Element) edge.getElementsByTagName("UML2:ActivityEdge.target").item(0);
        Node target = group.getChildNodes().item(0);
        Element targetRef = (Element) target;
        Element t = searchById(doc,targetRef.getNodeName(),targetRef.getAttribute("xmi.idref"));
        nameList.add(t.getAttribute("name"));

The searchById method is working (I use it in various parts of my code) but if you think it might be the problem, I’ll post it. Note that I use getChildNodes rather than getElementsByTagName because the target of this edge might not always be an activity (an XOR join/Merge Node for example). The exact error is :

com.sun.org.apache.xerces.internal.dom.DeferredTextImpl cannot be cast to org.w3c.dom.Element

When I try to cast ‘target’ to Element… I guess this comes from the fact that it is a “inline” tag but I have no idea how to treat it, being a beginner at parsing…

Thanks for your help,

Herve

Edit : I tried by replacing the getChildNodes by getElementsByTagName and it seems to work… However, if someone could correct the above code or at least explain why it won’t work properly, that would be awesome.

  • 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-08T14:34:20+00:00Added an answer on June 8, 2026 at 2:34 pm

    In short, you’re making a bad assumption that getChildNodes() returns only XML Elements; it doesn’t, it returns other kinds of nodes as well, including text nodes that represent the whitespace and newlines between the elements you’re interested in.

    If you want to call getChildNodes() and process all the nodes, then you need to loop over all the returned nodes, and look at each one to determine what sort of node it is, and process it accordingly. If you don’t want to do this, then something like getElementsByTagName() is the alternative.

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

Sidebar

Related Questions

i'm trying to write a simple app with node.js to pull some json from
I am currently trying to write some code that will accept some FTP details,
I am currently trying to get a script to write output from other started
I'm currently trying to write a simple script that looks in a folder, and
I am currently trying to write a very simple app that sends an object
I'm trying to write a simple program that will compare the files in separate
I'm trying to write a bitmap (.bmp) parser/reader by reading raw bytes from the
I'm currently trying to write a simple ORM with PHP and mysql. I want
I am currently trying to write an application that displays live video from a
I'm trying to write a simple lightweight image browser in Java, currently I'm using

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.