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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:56:08+00:00 2026-05-18T01:56:08+00:00

I am using XOM to canonicalize some XML. But there are some strange characters

  • 0

I am using XOM to canonicalize some XML. But there are some strange characters prepended to the output. The core of the code is as follows:

String result;
outputstream = new ObjectOutputStream(bytestream);
Builder builder = new Builder();
Canonicalizer canonicalizer = new Canonicalizer(outputstream, Canonicalizer.EXCLUSIVE_XML_CANONICALIZATION);
nu.xom.Document input = builder.build(xml, uri);
Node node = input.getRootElement();
String xpath = "//a:head";
XPathContext context = new XPathContext("a", "http://example.com/a");
Nodes nodes = node.query(xpath, context);
if (nodes.size() > 0) {
    canonicalizer.write(nodes.get(0));
    outputstream.close();
    result = bytestream.toString("UTF8");
}

xml contained

<a:envelope   xmlns:b='http://example.com/b'   xmlns:a="http://example.com/a">
  <a:document>
    <a:head>
      <b:this>this</b:this>
      <b:that>that</b:that>
      <b:what />
    </a:head>
    <a:body>
    </a:body>
  </a:document>
</a:envelope>

When the result is displayed in a JTextarea, there are six unexpected characters shown before the first <. The decimal values of the bytes in the bytestream are -84,-19,0,5,119,-36,60. (this is followed by canonical XML).

What am I doing wrong?

  • 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-18T01:56:09+00:00Added an answer on May 18, 2026 at 1:56 am

    The problem was that I had, for some reason I can’t fathom, Wrapped a ByteArrayOutputStream in an ObjectOutputStream. So presumably the output is prefixed with some serialization of an object’s metadata.

    I just used the ByteArrayOutputStream directly and the output is now as I expect.

        String result = "error";
        String uri = "http://example.com/uri";
        String xpath = textArea.getText();
        ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
        try {
            Builder builder = new Builder();
            Canonicalizer canonicalizer = new Canonicalizer(bytestream, 
                    Canonicalizer.EXCLUSIVE_XML_CANONICALIZATION);
            nu.xom.Document input = builder.build(xml, uri);
            Node node = input.getRootElement();
            XPathContext context = new XPathContext("a", "http://example.com/a");
            Nodes nodes = node.query(xpath, context);
            if (nodes.size() > 0) {
                canonicalizer.write(nodes.get(0));
                bytestream.close();
                result = bytestream.toString("UTF8");
            }
        catch (...){ ... }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using XOM to build XML documents in Java. I have created a
Using ASP.NET MVC there are situations (such as form submission) that may require a
Using C# .NET 3.5 and WCF, I'm trying to write out some of the
Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters
Using preview 4 of ASP.NET MVC Code like: <%= Html.CheckBox( myCheckBox, Click Here, True,
I'm using XOM with the following sample data: Element root = cleanDoc.getRootElement(); //find all
Is it possible to convert nu.XOM.Element to org.w3c.dom.Element ? Am trying to construct XML
Say I want to output a huge set of search results, as XML, into
I've looked into XOM but it seems that it doesn't work on mobile phones
Using jQuery's UI Tabs. This is my code. <div id=tabs> <ul> <li><a href=#tabs-1>Find a

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.