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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:04:19+00:00 2026-06-18T15:04:19+00:00

I have a task to correct the syntax of xml files if they are

  • 0

I have a task to correct the syntax of xml files if they are not well formatted. Currently I am doing this task manually. Is there any way to validate the syntax of XML file, if XML is not well formatted then correct it to well formatted?

Is it possible to validate and correct with Perl script?

Thanks,

  • 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-18T15:04:20+00:00Added an answer on June 18, 2026 at 3:04 pm

    XML::LibXML is a validating parser. You can use it to determine if the XML is valid.

    use XML::LibXML qw( );
    my $parser = XML::LibXML->new();
    if (eval { $parser->parse_file($qfn) }) {
       print "ok\n";
    } else {
       print "error:\n$@";
    }
    

    Automatically correcting XML is another matter. It’s impossible to automatically fix bad XML without making huge assumptions. For example, there’s no way to know whether

    <foo>/bar<baz/</foo>
    

    was meant to be

    <foo>/bar&lt;baz/</foo>
    

    or

    <foo>/bar<baz/></foo>
    

    or even something else.

    XML::LibXML does have an option to automatically fix/ignore some errors. Who knows if it makes the same assumption you do. Use

    use XML::LibXML qw( );
    my $parser = XML::LibXML->new( recover => $recover );
    my $doc = $parser->parse_file($in_qfn);
    $doc->toFile($out_qfn);
    

    Use 1 for $recover if you want the parser to be warn when it fixes a problem.
    Use 2 for $recover if you want the parser to fix problems silently.
    No matter what you use for $recover, it will still throw an exception if it encounters an unrecoverable error.

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

Sidebar

Related Questions

I would like to know the correct way of doing this task, I have
I have task involving reading SAS .xpt files using .NET. For that I'm using
I am new this sharepoint development and i have task in hand to do
maybe I will not correct explain a problem, maybe somebody help me explain this
Let's say I have a very simple task like this: @celery.task(ignore_result=True) def print_page(page): with
I have this task: realize Grails application with ExtJS. And one part of this
i have task which takes a parameter and has three modes of results Example
I'm using dhtmlx Gantt Chart UI component which have task list and graphical chart.
I have some task regarding do operations on database using ADODB in Vb.NET. Can
I have a task to do, I need to take data that has been

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.