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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:54:51+00:00 2026-06-17T10:54:51+00:00

I have an xml like this: <Message xmlns=uri_of_message> <VendorId>1234</VendorId> <SequenceNumber>1</SequenceNumber> …other important headers… <Data>

  • 0

I have an xml like this:

<Message xmlns="uri_of_message">
  <VendorId>1234</VendorId>
  <SequenceNumber>1</SequenceNumber>
  ...other important headers...
  <Data>
    <Functions xmlns="uri_of_functions_subxml">
      <Function1 attr="sth">
        <Info>Some_Info</Info>
      </Function1>
      <Function2>
        <Info>Some_Info</Info>
      </Function2>
      ...Functions n...
    </Functions>
  </Data>
</Message>

I need to extract inner xml

<Functions xmlns="uri_of_functions_subxml">
  <Function1 attr="sth">
    <Info>Some_Info</Info>
  </Function1>
  <Function2>
    <Info>Some_Info</Info>
  </Function2>
  ...Functions n...
</Functions>

I have firstly tried getting inner xml with characters method:

 public void startElement(String uri, String localName, String tagName, Attributes attributes) throws SAXException {
if (tagName.equalsIgnoreCase("Data")){
  buffer = new StringBuffer();}
}
public void characters(char[] ch, int start, int length) throws SAXException {
  if (buffer != null) {
     buffer.append(new String(ch, start, length).trim());
  }
}
public void endElement(String uri, String localName, String tagName) throws SAXException {
if (tagName.equalsIgnoreCase("Data")){
innerXML = buffer.toString().trim();
}

But then i have realized that characters method haven’t collected xml properly, it might have refused the special characters like “<“, “>”.

Link below contains same question but the answer is not applicable for me because the outer xml must be processed as sort of handshake signal, the inner xml must be processed in totally different way.

Java XML parsing: taking inner XML using SAX

Only thing that I need is to collect inner xml properly. But, how to do it?
Thanks in advance..

  • 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-17T10:54:52+00:00Added an answer on June 17, 2026 at 10:54 am

    SAX seems to be not the best choice for the job, anyway try

        SAXParser p = SAXParserFactory.newInstance().newSAXParser();
        XMLReader filter = new XMLFilterImpl(p.getXMLReader()) {
            private boolean inFunctions;
    
            @Override
            public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
                if (!inFunctions && qName.equals("Functions")) {
                    inFunctions = true;
                }
                if (inFunctions) {
                    super.startElement(uri, localName, qName, atts);
                } else {
                    qName.equals("Functions");
                }
            }
    
            @Override
            public void endElement(String uri, String localName, String qName) throws SAXException {
                if (inFunctions) {
                    super.endElement(uri, localName, qName);
                    if (qName.equals("Functions")) {
                        inFunctions = false;
                    }
                }
            }
    
            @Override
            public void characters(char[] ch, int start, int length) throws SAXException {
                if (inFunctions) {
                    super.characters(ch, start, length);
                }
            }
        };
        Transformer t = TransformerFactory.newInstance().newTransformer();
        Source source = new SAXSource(filter, new InputSource(new FileInputStream("1.xml")));
        Result result = new StreamResult(System.out);
        t.transform(source, result);
    }
    

    output

    <?xml version="1.0" encoding="UTF-8"?><Functions xmlns="uri_of_functions_subxml">
          <Function1 attr="sth">
            <Info>Some_Info</Info>
          </Function1>
          <Function2>
            <Info>Some_Info</Info>
          </Function2>
        </Functions>
    

    Official Tutorial

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

Sidebar

Related Questions

I have code like this: // Take the xml message and turn it into
I have some xml like this: <Data> <Rows> <Row> <Field Name=title>Mr</Field> <Field Name=surname>Doe</Field> <Row>
hi i have an xml like this <?xml version=1.0?> <DataSetExchangeWMS xmlns=http://tempuri.org/DataSetExchangeWMS.xsd> <dtObjektInfo> <LanguageCode>1031</LanguageCode> <LiegenschaftID>7463</LiegenschaftID>
I have an XML like: <message xmlns:gtm=http:// www.example.com/working/gtm> <gtm:header> <someid></someid> <sometext></sometext> </gtm:header> <gtm:customer>0123456789</gtm:customer> </message>
I have a question. My input XML looks like <?xml version=1.0 encoding=UTF-8?> <Text> <Message>this
I have an XML document that looks like this: <?xml version=1.0 encoding=UTF-8?> <xs:msgdata xmlns:xs=http://www.myCompany.com
I have xml like this: <rule> <word>I</word> <word>need</word> <word>more</word> <marker> <word>money</word> </marker> <word>now</word> </rule>
I have xml like this: <configurationData> <path name='b'> <path name='a'> <setting name='s1'> ![CDATA[XXXX]] </setting>
Let's suppose I have xml like this one: <Server Active=No> <Url>http://some.url</Url> </Server> C# class
I have xml structure like this: <Group id=2 name=Third parentid=0 /> <Group id=6 name=Five

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.