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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:28:48+00:00 2026-05-28T06:28:48+00:00

I am working on an xml writer for a format conversion. I decided to

  • 0

I am working on an xml writer for a format conversion. I decided to use the StAX API (the cursor API to be exact) because of the streaming capabilities (the input file is quite large and needs to be written segment by segment). I am using a data format (some classes) to store the parsed values from the input file. I also created some classes for the writing of the xml file , that have a writeNode method. This method looks like this:

public void writeNode(Object object){
writer.writeStartElement();
... some writeNode calls of the children nodes
writer.writeEndElement();

}

The object with the name “writer” is an instance of the StAXStreamWriter class.
My problem is, that sometimes these children nodes are empty. In these cases the parent nodes should not be written at all. Right now I am generating empty nodes, because the start tag of the current node is already be written. As far as i know this cannot be reversed.
Any ideas to solve this problem?

best regards

Lars

Update:

I think, I found a solution. I will write my own class, that implements the XMLStreamWriter interface. In this class I will use a queue or list data structure to store the start tags until the first attribute or node value is written.

Update 2:

Here is a more precise description of my solution. I used the decorator design pattern in order to wrap my new class around the standard streamwriter class. This class has an ArrayList, in which the Start Tags are stored until a writeCharacter method is called.

  • 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-28T06:28:49+00:00Added an answer on May 28, 2026 at 6:28 am

    when going though the XML File, you can get the current Event by xmlStreamReader.getEventType(). When you encounter XMLStreamConstants.START_ELEMENT, you could keep the opening Tag-Names, for instance in an Collection that keeps the insertation order (like LinkedHashSet).

    When you then encounter XMLStreamConstants.CHARACTERS, do a .getText() and write the previously stored Tags to the xmlStreamWriter, but only if this Text is not empty (maybe you also want to .trim() the .getText()-Result).

    Regards,
    Max

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

Sidebar

Related Questions

I'm working on Open XML document format for excel sheets. var nodeList = WorksheetXml.SelectNodes(@//c[child::f]);
I'm working on utility method that allows conversion of XML data into formatted String
I am new to XSLT and working on converting one format of XML to
my question is the following, which is the best way of working XML (kml)
I'm working with XML that was designed by somebody who got paid by the
I'm working with XML data from an application where we get XML like this:
I'm working with XML and Flash. I tried to pass XML values to my
I'm relatively new to working with XML and am working with some rather large
I recently read Ayende's blog post on automatic registration working with XML Configuration. I
I'm working with an XML document that contains a structure that looks similar to

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.