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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:45:46+00:00 2026-06-02T14:45:46+00:00

I am using Java to read an RSS feed from a URL, parse the

  • 0

I am using Java to read an RSS feed from a URL, parse the DOM tree using javax.xml.parsers.DocumentBuilder.parse(InputStream), make some changes to it, then serialize and output the result using org.w3c.dom.ls.LSSerializer.write(Node,LSOutput).

The feed I’m reading is http://www.collaborationblueprint.com.au/blog/rss.xml.

The feed is well-formed XML, but the serialization result is not.
On every attempt so far, CData sections have been broken by the removal of one pair of square brackets.
E.g. If the source contains the following element:

    <description><![CDATA[<p>some text</p>]]></description>

The serialized result looks like this, and is not well-formed:

    <description><![CDATA<p>some text</p>]></description>

My code is below. It’s contained in a Lotus Domino agent.
How do I fix this problem?

import java.io.InputStream;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLDecoder;
import java.util.HashMap;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.bootstrap.DOMImplementationRegistry;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSOutput;
import org.w3c.dom.ls.LSSerializer;

import lotus.domino.*;

public class JavaAgent extends AgentBase {
    public void NotesMain() {
        try {
            org.w3c.dom.Document newDoc;
            DocumentBuilderFactory builderFactory;
            DocumentBuilder builder;
            Element docElem,tmpElem;
            Node tmpNode;

            Session session=getSession();
            AgentContext agentContext=session.getAgentContext();

            // Put URL arguments into a HashMap.
            Document doc=agentContext.getDocumentContext();
            String[] query=doc.getItemValueString("Query_String").split("&");

            HashMap<String,String> queryMap=new HashMap<String,String>(query.length);
            for (int i=0; i<query.length; i++) {
                int j=query[i].indexOf('=');
                if (j<0) queryMap.put(query[i],"");
                else queryMap.put(query[i].substring(0,j),URLDecoder.decode(query[i].substring(j+1),"UTF-8"));
            }

            // Get the "src" URL argument - this is the URL we're reading the feed from.
            String urlStr=queryMap.get("src");
            if (urlStr==null || urlStr.length()==0) {
                System.err.println("Error: source URL not specified.");
                return;
            }
            URL url;
            try {
                url=new URL(urlStr);
            } catch (Exception e) {
                System.err.println("Error: invalid source URL.");
                return;
            }

            HttpURLConnection conn=(HttpURLConnection)url.openConnection();
            InputStream is=conn.getInputStream();

            builderFactory=DocumentBuilderFactory.newInstance();
            builder=builderFactory.newDocumentBuilder();

            // Create a DocumentBuilder and parse the XML.
            builder=builderFactory.newDocumentBuilder();
            try {
                newDoc=builder.parse(is);
                is.close();
                conn.disconnect();
            } catch (Exception e) {
                is.close();
                conn.disconnect();
                System.err.println("XML parse exception: "+e.toString());
                return;
            }

            docElem=newDoc.getDocumentElement();
            docElem.setAttribute("xmlns:ibmwcm","http://purl.org/net/ibmfeedsvc/wcm/1.0");

            PrintWriter pw=getAgentOutput();
            pw.println("Content-type: text/xml");

            DOMImplementationRegistry registry=DOMImplementationRegistry
                .newInstance();
            DOMImplementationLS impl=(DOMImplementationLS)registry
                .getDOMImplementation("LS");
            LSOutput lso=impl.createLSOutput();
            lso.setCharacterStream(pw);
            LSSerializer writer=impl.createLSSerializer();
            writer.write(newDoc,lso);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
  • 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-02T14:45:47+00:00Added an answer on June 2, 2026 at 2:45 pm

    I’ve determined the problem is nothing to do with the serializer.

    Even if I do something as simple as:

        pw.print("<description><![CDATA[<p>Some text</p>]]></description>");
    

    the inner pair of square brackets gets stripped.

    However, if I encode less-than signs in the CData, the problem goes away. E.g.:

        pw.print("<description><![CDATA[&lt;p>Some text&lt;/p>]]></description>");

    I have not yet determined whether the cause is the PrintWriter class or Lotus Domino, but regardless I should be able to modify the XML between parsing and serialization to fix it.

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

Sidebar

Related Questions

How to read RSS Feed by using Java Script. As I am Android developer
I am trying to read RSS feed in java I am using ROME to
How can I read from a Windows shared drive using Java in such a
I am trying to read an external rss feed using a xAgent, I seem
I need to read an XML file using Java. Its contents are something like
I am using Java 6 and want to process (read and write) xml files
Problem : Trying to read from some electronic scales using the comport via Java
I am trying to read data from the given web page using Java. public
I'm designing a tool using Java 6, that will read data from Medical Devices.
I want to read barcode from barcode device using Java. Please guide me.

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.