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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:53:26+00:00 2026-06-14T20:53:26+00:00

How to convert an invalid XML to Valid XML according given xsd-schema? For example,

  • 0

How to convert an invalid XML to Valid XML according given xsd-schema?
For example, I have next xsd schema:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="note">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="to" type="xs:string"/>
      <xs:element name="from" type="xs:string"/>
      <xs:element name="heading" type="xs:string"/>
      <xs:element name="body" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>
</xs:schema>

and next invalid XML:

<?xml version="1.0" encoding="UTF-8"?>
<note xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../my_xsd.xsd">
  <to>reviver@mail.com</to>
  <from>sender@mail.com</from>
  <body>blablabla</body> <!-- IVALID LINE, IT IS NOT IN RIGHT PALCE -->
  <heading>head</heading>
</note>

My question is: Do JAXB, XSTREAM, or other XML parsers have solution to convert my invalid XML according given schema to valid XML:

<?xml version="1.0" encoding="UTF-8"?>
<note xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../my_xsd.xsd">
  <to>reviver@mail.com</to>
  <from>sender@mail.com</from>
  <heading>head</heading>
  <body>blablabla</body>
</note>
  • 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-14T20:53:28+00:00Added an answer on June 14, 2026 at 8:53 pm

    Assumption: I’ll assume the input is well-formed XML.

    In general, the answer is no… no algorithm would be able to convert an arbitrary XML input document to a valid and semantically correct instance of a given schema.

    However, if the ways in which the input can be invalid are constrained to just a small set of problems, such as child elements of <note> being out of order, then yes, just about any XML parsing and serialization library could help you fix the problem. As @KevinDTimm alluded to, you’ll want to turn off schema validation in these tools so that they don’t reject the input before fixing it.

    Personally I would use XSLT since that’s what I’m used to. You could have it read the child elements in whatever order they occur, and output them as XML in the correct order:

    <xsl:template match="note">
      <xsl:copy>
        <xsl:apply-templates select="to" />
        <xsl:apply-templates select="from" />
        <xsl:apply-templates select="heading" />
        <xsl:apply-templates select="body" />
      </xsl:copy>
    </xsl:template>
    

    But the example tools you list – JAXB and XSTREAM – are not merely XML parsers, but XML object parsers/serializers. If you need to correct validation errors while building an object, that would complicate things. A separate process of correcting, and then deserializing, would be simpler.

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

Sidebar

Related Questions

I have this xml: <?xml version=1.0 encoding=utf-8 ?> <Interfaces> <Interface> <Name>Account Lookup</Name> <PossibleResponses> <Response>Account
I convert all links from example.com/action to example.com/index.html#action which is then parsed by my
AIM : Convert a resultset to XML and assign the result to a variable
I'm trying convert xml from one format to other using the XslCompiledTransform in c#.
I need to convert data in plain text columns into xml columns. However, not
Is there any classes to convert ascii to xml characterset preferably opensource i will
When validating my XML sitemap , google says: Invalid date An invalid date was
How can you convert a drive relative path such as D:test.xml into an absolute
I have a WordPress xml data file encoding with utf-8. But the WordPress impoter
I have to create xml after reading from a datatable, in C# application. This

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.