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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:54:41+00:00 2026-05-21T15:54:41+00:00

I’m trying to parse an XML file with big text inside of the tags.

  • 0

I’m trying to parse an XML file with big text inside of the tags. Sometimes the texts have carriage returns in them. When I debug, my String gets overwritten with a carriage return (“\n”) which sometimes leads to an ampty string or a string with just one line.

I have no control on how the data is stored in the database, I can just read it in XML. Some people put a carriage return behind each tag, this leads to the empty strings.

Example of an XML file:

<?xml version="1.0" encoding="utf-8" ?> 
<vacaturedetails>
<details>
<titel>MEDEWERKER VOOR ONDERHOUDSDIENST</titel> 
<werkveld>METAALMECHANICA</werkveld> 
<regio>Regio Roeselare- Izegem</regio> 
<tewerkstellingsplaats>Bedrijf in Roeselare met goeie reputatie.</tewerkstellingsplaats> 
<diploma1>A2 (Beroeps + 7ej, Technisch, ASO)</diploma1> 
<diploma2>A3 (Beroeps tot 6e j, Deeltijds, Leercontract)</diploma2> 
<taal1>Nederlands</taal1> 
<ervaring>6 maand - 2 jaar</ervaring> 
<rijbewijs>B</rijbewijs> 
<rijbewijsOmsch>Auto</rijbewijsOmsch> 
<omschrijving>- Inzicht in, en zelfstandig kunnen monteren en lassen van metalen constructies. - Hulp bij het ontwikkelen van nieuwe constructies van onderdelen in de productielijn of verbeteren van bestaande constructies. - Kunnen rijden met heftruck en werken met hoogtewerker. - Plaatsen van leidingen voor perslucht, water, ...en sanitair. - Kleine herstellingen uitvoeren. - Hulp bij verhuis binnen het bedrijf. - Allerhande klusjes die nodig zijn aan en rond de bedrijfsgebouwen. </omschrijving> 
<aanbod>Dagwerk met een goeie verloning in een goei werksfeer. Optie vast na uitzendperiode.    </aanbod> 
<profiel>- Kunnen lassen met halfautomaat, kennis autogeen lassen is een pluspunt. - Kunnen rijden met heftruck (attest is een pluspunt) en werken met hoogtewerker. - Inzicht hebben en zelfstandig kunnen monteren van constructies. - Kennis van sanitair (water, gas, perslucht) - Ervaring is een must!</profiel> 
</details>
</vacaturedetails>

This is how my parser looks:

package stage.accent.webservice;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import stage.accent.domain.VacatureDetails;

public class vacatureDetailsWebservice extends DefaultHandler {

private boolean vacaturedetailstag = false;
private boolean detailstag = false;
private boolean titeltag = false;
private boolean werkveldtag = false;
private boolean tewerkstellingsplaatstag = false;
private boolean diploma1tag = false;
private boolean diploma2tag = false;
private boolean taal1tag = false;
private boolean taal2tag = false;
private boolean taal3tag = false;
private boolean taal4tag = false;
private boolean taal5tag = false;
private boolean ervaringtag = false;
private boolean omschrijvingtag = false;
private boolean aanbodtag = false;
private boolean profieltag = false;
private boolean rijbewijstag = false;
private boolean rijbewijsOmschtag = false;

private String test;


//private Vacature vacature = new Vacature();
private VacatureDetails details;

public VacatureDetails getVacatures() {
    return this.details;

}

@Override
public void startDocument() throws SAXException {

    this.details = new VacatureDetails();
}

@Override
public void endDocument() throws SAXException {
    // Nothing to do
}

/** Gets be called on opening tags like: 
 * <tag> 
 * Can provide attribute(s), when xml was like:
 * <tag attribute="attributeValue">*/
@Override
public void startElement(String namespaceURI, String localName,
        String qName, Attributes atts) throws SAXException {
    if (localName.equals("vacaturedetails")) {
        this.vacaturedetailstag = true;             
    }else if (localName.equals("details")) {
        this.detailstag = true;
    }else if (localName.equals("titel")) {
        this.titeltag = true;
    }else if (localName.equals("werkveld")){
        this.werkveldtag = true;
    }else if (localName.equals("tewerkstellingsplaats")){
        this.tewerkstellingsplaatstag = true;
    }else if (localName.equals("diploma1")){
        this.diploma1tag = true;
    }else if (localName.equals("diploma2")){
        this.diploma2tag = true;
    }else if (localName.equals("taal1")){
        this.taal1tag = true;
    }else if (localName.equals("taal2")){
        this.taal2tag = true;
    }else if (localName.equals("taal3")){
        this.taal3tag = true;
    }else if (localName.equals("taal4")){
        this.taal4tag = true;
    }else if (localName.equals("taal5")){
        this.taal5tag = true;
    }else if (localName.equals("ervaring")){
        this.ervaringtag = true;
    }else if (localName.equals("rijbewijs")){
        this.rijbewijstag = true;
    }else if (localName.equals("rijbewijsOmsch")){
        this.rijbewijsOmschtag = true;
    }else if (localName.equals("omschrijving")){
        this.omschrijvingtag = true;
    }else if (localName.equals("aanbod")){
        this.aanbodtag = true;
    }else if (localName.equals("profiel")){
        this.profieltag = true;
    }
}

/** Gets be called on closing tags like: 
 * </tag> */
@Override
public void endElement(String namespaceURI, String localName, String qName)
        throws SAXException {
    if (localName.equals("vacaturedetails")) {
        this.vacaturedetailstag = false;
    }else if (localName.equals("details")) {
        this.detailstag = false;
    }else if (localName.equals("titel")) {
        this.titeltag = false;
    }else if (localName.equals("werkveld")){
        this.werkveldtag = false;
    }else if (localName.equals("tewerkstellingsplaats")){
        this.tewerkstellingsplaatstag = false;
    }else if (localName.equals("diploma1")){
        this.diploma1tag = false;
    }else if (localName.equals("diploma2")){
        this.diploma2tag = false;
    }else if (localName.equals("taal1")){
        this.taal1tag = false;
    }else if (localName.equals("taal2")){
        this.taal2tag = false;
    }else if (localName.equals("taal3")){
        this.taal3tag = false;
    }else if (localName.equals("taal4")){
        this.taal4tag = false;
    }else if (localName.equals("taal5")){
        this.taal5tag = false;
    }else if (localName.equals("ervaring")){
        this.ervaringtag = false;
    }else if (localName.equals("rijbewijs")){
        this.rijbewijstag = false;
    }else if (localName.equals("rijbewijsOmsch")){
        this.rijbewijsOmschtag = false;
    }else if (localName.equals("omschrijving")){
        this.omschrijvingtag = false;
    }else if (localName.equals("aanbod")){
        this.aanbodtag = false;
    }else if (localName.equals("profiel")){
        this.profieltag = false;
    }
}

/** Gets be called on the following structure: 
 * <tag>characters</tag> */
@Override
public void characters(char ch[], int start, int length) {
    if(this.titeltag){
        details.setTitel(new String(ch, start, length));
    }
    if(this.werkveldtag){
        details.setWerkveld(new String(ch, start, length));
    }
    if(this.tewerkstellingsplaatstag){
        details.setTewerkstellingsplaats(new String(ch, start, length));

    }
    if(this.diploma1tag){
        details.setDiploma1(new String(ch, start, length));
    }
    if(this.diploma2tag){
        details.setDiploma2(new String(ch, start, length));
    }
    if(this.taal1tag){
        details.setTaal1(new String(ch, start, length));
    }
    if(this.taal2tag){
        details.setTaal2(new String(ch, start, length));
    }
    if(this.taal3tag){
        details.setTaal3(new String(ch, start, length));
    }
    if(this.taal4tag){
        details.setTaal4(new String(ch, start, length));
    }
    if(this.taal5tag){
        details.setTaal5(new String(ch, start, length));
    }
    if(this.ervaringtag){
        details.setErvaring(new String(ch, start, length));
    }
    if(this.rijbewijstag){
        details.setRijbewijs(new String(ch, start, length));
    }
    if(this.rijbewijsOmschtag){
        details.setRijbewijsOmsch(new String(ch, start, length));
    }           
    if(this.omschrijvingtag){
        details.setOmschrijving(new String(ch, start, length));
    }
    if(this.aanbodtag){
        details.setAanbod(new String(ch, start, length));
    }
    if(this.profieltag){
        details.setProfiel(new String(ch, start, length));
    }
    test = details.toString();
}

}

The output of this Example of omschrijving was = - Allerhande klusjes die nodig zijn aan en rond de bedrijfsgebouwen.

Is there any way to parse this, so that the full text with carriage returns appear in my String.

  • 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-21T15:54:42+00:00Added an answer on May 21, 2026 at 3:54 pm

    I understand that you overwrite the value of that tag always with the last chunk.
    Replace this piece of code in the method characters

    if(this.omschrijvingtag){
        details.setOmschrijving(new String(ch, start, length));
    }
    

    with

    if(this.omschrijvingtag){
        details.setOmschrijving((details.getOmschrijving() != null? details.getOmschrijving() : "") + new String(ch, start, length));
    }
    

    EDIT: basically, what you do is you check whether the value of Omschrijving is set or not and act accordingly. In case this code confuses you, check out the same thing as a little bit a different expression

    if(this.omschrijvingtag){
        if(details.getOmschrijving() != null) {
            details.setOmschrijving(details.getOmschrijving() + new String(ch, start, length));
        }
        else {
            details.setOmschrijving(new String(ch, start, length));
        }
    }
    

    So you check whether the value of Omschrijving is empty and if it’s not, you concatenate the already existing value, otherwise you just assign the new value. That’s pretty much it.

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

Sidebar

Related Questions

I have a reasonable size flat file database of text documents mostly saved in
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
Basically, what I'm trying to create is a page of div tags, each has
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a text area in my form which accepts all possible characters from

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.