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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:33:24+00:00 2026-05-25T23:33:24+00:00

I create an xml document in C# by converting a string to bytes via

  • 0

I create an xml document in C# by converting a string to bytes via System.Text.UTF8Encoding(). I then send this to my java program for xmlbeans to parse via a TCP connection. No matter what i try, i am getting this error:
org.apache.xmlbeans.XmlException: error: Illegal XML character: 0x0
org.apache.xmlbeans.impl.piccolo.io.IllegalCharException: Illegal XML character: 0x0

I have attempted to sanitize the the string on the C# side, yet it does not find any instance of 0x0. I have looped through and output each byte in the byte[] that i receive on the java side, and there is absolutely nothing that has a 0x0.

This is my java side code:

    public void parseBytes(byte[] bytes, int length, String source)
{
    System.out.println("***************BmsDrawingGatewayParser - ParseBytes  " + length);        

    String foundData = null;
    try
    {
        foundData = new String(bytes, 0, length, "UTF-8");
    }
    catch (UnsupportedEncodingException e1)
    {
        e1.printStackTrace();
    }
    switch (readState)
    {             
    case STATE_NEW_MSG:
        // if contains the 
        if (foundData.contains(startMessageTag))
        {
            if (foundData.contains(endMessageTag))
            {   
                byteStream.write(bytes, 0, length);                   
                parseXml(byteStream.toByteArray());
                if (byteStream.size() > 0)
                {
                    byteStream.reset();
                }
            }
            else
            {                    
                readState = DrawingDeviceParserState.STATE_READING_MSG;
            }                
        }
        else
        {
            System.out.println("Couldn't find start tag");
            System.out.println(foundData);
        }
        break;

    case STATE_READING_MSG:          
        byteStream.write(bytes, byteStream.size(), length);
        if (foundData.contains(endMessageTag))
        {
            System.out.println("Now going to parse");
            //parseXml(xmlString.toString());
            parseXml(byteStream.toByteArray());
            byteStream.reset();
            readState = DrawingDeviceParserState.STATE_NEW_MSG;
        }
        else
        {
            System.out.println("Couldn't find end tag");
            System.out.println(foundData);
        }
        break;
    }                        
}

    private void parseXml(byte[] xmlData)
    {
        System.out.println(xmlData);

        //EventDocument.Factory.parse
        ByteArrayInputStream sid = new ByteArrayInputStream(xmlData);     
        try
        {
            EventDocument eventDoc = EventDocument.Factory.parse(sid);
            if (eventDoc.validate())
            {
                System.out.println("Document is valid");
            }
            else
            {
                System.out.println("Document is INVALID");
            }
            EventDocument.Event myEvent = eventDoc.getEvent();
            EventDocument.Event.Detail[] myDetailArray = myEvent.getDetailArray();

            //myDetailArray[0].

            //BmsDrawingDocument drawingDoc = myEvent.getDetail();
            System.out.println("MY UID: " + myEvent.getUid());
        }
        catch(Exception xmlException)
        {
            System.out.println(xmlException.toString());
            xmlException.printStackTrace();
        }
}

Does anyone know what i might be doing wrong? Is there more information that i can provide?

  • 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-25T23:33:24+00:00Added an answer on May 25, 2026 at 11:33 pm
    public void parseBytes(byte[] bytes, int length, String source)
    {               
        String foundData = null;
        try
        {
            foundData = new String(bytes, 0, length, "UTF-8");
        }
        catch (UnsupportedEncodingException e1)
        {
            e1.printStackTrace();
        }
        switch (readState)
        {             
        case STATE_NEW_MSG:
            // if contains the 
            if (foundData.contains(startMessageTag))
            {
                if (foundData.contains(endMessageTag))
                {   
                    byteStream.write(bytes, 0, length);                   
                    parseXml(byteStream.toByteArray());
                    if (byteStream.size() > 0)
                    {
                        byteStream.reset();
                    }
                }
                else
                {                    
                    readState = DrawingDeviceParserState.STATE_READING_MSG;
                }                
            }
            else
            {
                System.out.println("Couldn't find start tag");
                System.out.println(foundData);
            }
            break;
    
        case STATE_READING_MSG:          
            byteStream.write(bytes, byteStream.size(), length);
            if (foundData.contains(endMessageTag))
            {
                System.out.println("Now going to parse");
                //parseXml(xmlString.toString());
                parseXml(byteStream.toByteArray());
                byteStream.reset();
                readState = DrawingDeviceParserState.STATE_NEW_MSG;
            }
            else
            {
                System.out.println("Couldn't find end tag");
                System.out.println(foundData);
            }
            break;
        }                        
    }
    
        private void parseXml(byte[] xmlData)
        {
            System.out.println(xmlData);
    
            //EventDocument.Factory.parse
            ByteArrayInputStream sid = new ByteArrayInputStream(xmlData);     
            try
            {
                EventDocument eventDoc = EventDocument.Factory.parse(sid);
                if (eventDoc.validate())
                {
                    System.out.println("Document is valid");
                }
                else
                {
                    System.out.println("Document is INVALID");
                }
                EventDocument.Event myEvent = eventDoc.getEvent();
                EventDocument.Event.Detail[] myDetailArray = myEvent.getDetailArray();
    
                //myDetailArray[0].
    
                //BmsDrawingDocument drawingDoc = myEvent.getDetail();
                System.out.println("MY UID: " + myEvent.getUid());
            }
            catch(Exception xmlException)
            {
                System.out.println(xmlException.toString());
                xmlException.printStackTrace();
            }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking to create XML Document objects in Java and serialize them to a
I need to create an XML document from a piece of plain text and
I am trying to create an XML document with multiple namespaces using System.Xml.Xmlwriter in
I get an XML from website into a string strXML. Then I create an
There seem to be many options to create an XML document in .NET. What's
I need to manipulate an existing XML document, and create a new one from
this is my situation: I have two org.w3c.dom.Document created from two xml files. What
I've encountered an issue whereby when I create an XML Document programmatically using the
I want create an xml document with the namepace attributes along the lines of
I need to create an XML document for a website service that shows products

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.