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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:52:56+00:00 2026-06-08T20:52:56+00:00

Quick question: if I have an XML like this one: <?xml version=1.0 encoding=utf-8?> <cop

  • 0

Quick question:

if I have an XML like this one:

<?xml version="1.0" encoding="utf-8"?>
<cop xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="cop.xsd">
    <auth>
        <uid mioattributo="20">16<![CDATA[
function matchwo(a,b) ]]></uid>
    </auth>
</cop>

so uid has two children right? One of Node.CDATA_SECTION_NODE and one of Node.TEXT_NODE.

Implementing this quick class (extending the usual DefaultHandler):

public class MyHandler extends DefaultHandler {
    /**
     * Logger for this class
     */
    private static final Log log = LogFactory.getLog(MyHandler.class);
    private StringBuilder sb;

    @Override
    public void startElement(String uri, String localName, String qName,
        Attributes attributes) throws SAXException {
    System.out.println("STARTUri: " + uri);
    System.out.println("STARTLocalName: " + localName);
    System.out.println("STARTqName: " + qName);
//  for(int i=0;i<attributes.getLength();i++) {
//      System.out.println("LocalName: "+attributes.getLocalName(i));
//      System.out.println("Type: "+attributes.getType(i));
//      System.out.println("qName: "+attributes.getQName(i));
//      System.out.println("URI: "+attributes.getURI(i));
//      System.out.println("Value: "+attributes.getValue(i));
//  }
    sb = new StringBuilder();
    //super.startElement(uri, localName, qName, attributes);
    }

    @Override
    public void characters(char[] ch, int start, int length)
            throws SAXException {
    sb.append(ch, start, length);
    System.out.println("TEMPORARY: " + sb.toString());
    System.out.println();
    }

    @Override
    public void endElement(String uri, String localName, String qName)
            throws SAXException {
    System.out.println("ENDUri: " + uri);
    System.out.println("ENDLocalName: " + localName);
    System.out.println("ENDqName: " + qName);
    System.out.println("Content: " + sb.toString());
    sb.replace(0, sb.length()-1,"");
    }

}

The parsing of the output would be something like:

Is Validating: true
STARTUri: 
STARTLocalName: cop
STARTqName: cop
TEMPORARY: 


STARTUri: 
STARTLocalName: auth
STARTqName: auth
TEMPORARY: 


STARTUri: 
STARTLocalName: uid
STARTqName: uid
TEMPORARY: 16

TEMPORARY: 16
function matchwo(a,b) 

ENDUri: 
ENDLocalName: uid
ENDqName: uid
Content: 16
function matchwo(a,b) 
TEMPORARY:  


ENDUri: 
ENDLocalName: auth
ENDqName: auth
Content:  

TEMPORARY:  


ENDUri: 
ENDLocalName: cop
ENDqName: cop
Content:    

From the output we can see that the method characters() is called twice inside the node uid so it recognizes the two children. Is there a way to know which one is the CDATA and which one is the TEXT?

  • 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-08T20:52:58+00:00Added an answer on June 8, 2026 at 8:52 pm

    You should look at the LexicalHandler which tells you about CDATA start/ends.

    Note that the SAX parser is at liberty to call your characters() method as many (or as few) times as it needs, in order for you to build up a string (which you only know is complete upon endElement() being called), and you can’t rely on it in order to determine document structure.

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

Sidebar

Related Questions

Quick question... I have a query that checks for duplicates that looks like this:
Just a quick question. I have one XML and I was hoping to tranform
Here's a quick one. In my navigation.xml I have this type of structure. <faq>
I have a quick question in reference to changing an RSS url http://www.bellyscarf.com/rsscategoryproducts.sc?categoryId=6 As
Hello i have a quick question. I get 2 flash messages, the devise one
Quick question. I have some XML <someXML> <someNode> </someNode> <someNode>asdlkjf </someNode> </someXML> When i
I have a quick question; when using cachedependency with an xml file, could a
quick question on tick data. I have tons of data under this format which
quick question, I have a <hr> and this script: <script type=text/javascript > $(function ()
I've just started learning XML & XSLT and have a quick question regarding Xpath.

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.