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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:35:55+00:00 2026-06-08T18:35:55+00:00

I want to parse a xml file in java which contains binary data: here

  • 0

I want to parse a xml file in java which contains binary data: here is an example of the xml file:

<?xml version="1.0" encoding="utf-8"?>
<documents>
  <document>
    <element name="docid">
      <value><![CDATA[0902307e8004c74c]]></value>
    </element>
    <element name="published">
      <value><![CDATA[2012-01-01T00:00:00]]></value>
    </element>
    <element name="documenttype">
      <value><![CDATA[Circular]]></value>
    </element>
    <element name="data">
      <value><![CDATA[%PDF-1.6
%����
1020 0 obj
<</Filter/FlateDecode/First 20/Length 270/N 3/Type/ObjStm>>stream
�o^���)|�,�Ypoef�
l���o�>����u���b"Cb�|���%&��D�yD��q�q�q�q�q��%_ja�LJob��/��3"=����o���]V11}�    }a�+'6@����C�,^}�d%�۠�`s��q��5�׷^(�N��{S<S�����A��������-������f\ڌ��|U/݌�z���f�I9����g�g���s���0z'��X~
endstream
endobj
startxref
55097
%%EOF
]]></value>
    </element>
    <element name="dataname">
      <value><![CDATA[sdfsfsfsdsdfsd.pdf]]></value>
    </element>
  </document>
</documents>

Normally I would parse such an xml file that way:

Document doc = null;
DocumentBuilder documentBuilder = null;
documentBuilderFactory = DocumentBuilderFactory.newInstance();
        try {
            documentBuilder = documentBuilderFactory.newDocumentBuilder();
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
        }
try {

            doc = documentBuilder.parse(fastXMLFile);

        } catch (SAXException e) {
            System.out.println("SAXExept");
            e.printStackTrace();
        } catch (IOException e) {
            System.out.println("Test");
            return;
        }

But because of the “data” element which contains binary data, the debugger tells me:

[Fatal Error] xmlfile.xml:58:10: An invalid XML character (Unicode: 0x1a) was found in the CDATA section.
SAXExept
org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0x1a) was found in the CDATA section.

I dont need to parse this data field by now, I could just skip it. I just want to parse the rest of the data. Is this possible?

  • 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-08T18:35:57+00:00Added an answer on June 8, 2026 at 6:35 pm

    Since your XML includes invalid characters (as the exception shows), you can’t expect libraries to parse it successfully. Since you can’t change the XML file creation process, and since you can’t see the code of the search engine, I believe the easiest for you will be to remove the Invalid characters from the XML.

    so the process would be:

    1- read the contents of the XML into a String

    2- parse the String and remove all Invalid Charachters

    3- write the String back into the file. or create a new file if you can’t modify the original

    4- parse the modified/new file.

    In order to replace invalid characters, see the following link as it also includes a method to do so.

    Invalid XML Characters: when valid UTF8 does not mean valid XML.

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

Sidebar

Related Questions

Given the following XML file: <?xml version=1.0 encoding=UTF-8?> <process name=TestSVG2 xmlns=http://www.example.org targetNamespace=http://www.example.org xmlns:xsd=http://www.w3.org/2001/XMLSchema> <sequence>
I want to parse xml file in utf-8 and sort it by some field.
I want to parse an XML file with Java and validate it in the
i want parse xml file, which does't have xml extension, like this: http://bizonek.wrzuta.pl/xml/plik/1ANdXCgTOit/unknow/undefined/643/ my
I want to parse an XML file using SAX parser in java with this
I have a big (1.9 GB) XML file which has data I want to
I want to parse an xml log file, using Java. The weird thing though
I want to parse the xml file with dynamic content using DOM parser in
I want to parse a xml file using xquery in Ruby, I found this
I want to parse a large XML file and I have two options: Perl

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.