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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:31:52+00:00 2026-06-11T12:31:52+00:00

I have been trying to validate XML file using schema file in my C

  • 0

I have been trying to validate XML file using schema file in my C Code. The validation happens successfully stating whether the file is valid or invalid.

But my issue is it prints valid/invalid only. There should be a report/output as to what was missing in the xml file in case it was invalid. May be something like the line number in XML file.

Hope, i have made my self clear.

Here’s my C code:-

 int validateXmlFile()
{
    int iError = 0;
    xmlDocPtr pDoc;
    xmlDocPtr pSchemaDoc;
    xmlSchemaParserCtxtPtr pSchemaCtxt;
    xmlSchemaPtr pSchema;
    xmlSchemaValidCtxtPtr pValidCtxt;
    char * xmlFilename = "C:\\Documents and Settings\\pbhatia\\Desktop\\Schema\\ipt_config.xml";
    char * schemaFilename = "C:\\Documents and Settings\\pbhatia\\Desktop\\Schema\\ipt_config.xsd";

    PRNT(printf("Schema file : %s \n", schemaFilename));
    PRNT(printf("XML file : %s \n", xmlFilename));

    pDoc = xmlReadFile(xmlFilename, NULL, XML_PARSE_NONET);
    if (!pDoc)
        return -1;

    pSchemaDoc = xmlReadFile(schemaFilename, NULL, XML_PARSE_NONET);
    if (!pSchemaDoc)
        return -2;

    pSchemaCtxt = xmlSchemaNewDocParserCtxt(pSchemaDoc);
    if (!pSchemaCtxt)
        return -3;

    pSchema = xmlSchemaParse(pSchemaCtxt);
    if (!pSchema)
        return -4;

    pValidCtxt = xmlSchemaNewValidCtxt(pSchema);
    if(!pValidCtxt)
        return -5;

    // Attempting to validate xml with schema
    xmlSchemaFreeParserCtxt(pSchemaCtxt);
    xmlFreeDoc(pSchemaDoc);

    iError = xmlSchemaValidateDoc(pValidCtxt, pDoc);
        if (iError == 0)
        PRNT(printf("Document in %s is valid \n", xmlFilename));
    else
        PRNT(printf("Document in %s is NOT valid \n", xmlFilename));

    xmlSchemaFree(pSchema);
    xmlFreeDoc(pDoc);
    return 0;
}

Thanks,
Priyanka

  • 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-11T12:31:53+00:00Added an answer on June 11, 2026 at 12:31 pm

    From reading xmllint.c source code it turns out that you may setup callbacks for errors and warnings in the context, using xmlSchemaSetValidErrors. In simplest case you forward fprintf and it would simply print errors.

    xmlSchemaSetValidErrors(ctxt,
        (xmlSchemaValidityErrorFunc) fprintf,
        (xmlSchemaValidityWarningFunc) fprintf,
        stderr);
    

    UTSL 🙂

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

Sidebar

Related Questions

Have been trying to encrypt an xml file to a string so that I
I've been trying to figure out how to use an XML Schema to validate
i have been trying to validate This Form: <table> <form action=test.html method=post id=contactform name=contactform>
Have have been trying to make a validator for my xml files. I have
I have been trying to create a ListView which I can sort using drag
I have been trying to make custom radio buttons using HTML, CSS, and JavaScript.
I am trying to validate weather the connection was successful but have been getting
I have been trying to wrap my head around creating a RESTFul API using
I have been trying to do this in ms visual studio 2008 using the
This is using jQuery 1.6.1 and Validate 1.8.1. I have been banging my head

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.