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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:44:51+00:00 2026-05-30T02:44:51+00:00

I am trying to validate an XML document against a dozen or so schemas

  • 0

I am trying to validate an XML document against a dozen or so schemas using Nokogiri. Currently I have a root schema document that imports all the other schemas, and I validate against that.

Can I point to each schema file from the XML file itself, and have Nokogiri look in the XML file for the schemas to validate against?

  • 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-30T02:44:53+00:00Added an answer on May 30, 2026 at 2:44 am

    The proper way to reference multiple schemata against which to validate an XML file is with the schemaLocation attribute:

    <?xml version="1.0"?>
    <foo xmlns="http://bar.com/foo"
         xmlns:bz="http://biz.biz/"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xsi:schemaLocation="http://bar.com/foo http://www.bar.com/schemas/foo.xsd
                             http://biz.biz/ http://biz.biz/xml/ns/bz.xsd">
    

    For each namespace in your document you list a pair of whitespace-delimited values: the namespace URI followed by a ‘hint’ as to where to find the schema for that namespace. If you provide a full URI for each hint, then you can process this with Nokogiri as such:

    require 'nokogiri'
    require 'open-uri'
    
    doc = Nokogiri.XML( my_xml )
    schemata_by_ns = Hash[ doc.root['schemaLocation'].scan(/(\S+)\s+(\S+)/) ]
    schemata_by_ns.each do |ns,xsd_uri|
      xsd = Nokogiri::XML.Schema(open(xsd_uri))
      xsd.validate(doc).each do |error|
        puts error.message
      end
    end
    

    Disclaimer: I have never attempted to validate a single XML document using multiple namespaced schemata with Nokogiri before. As such, I have no direct experience to guarantee that the above validation will work. The validation code is based solely on Nokogiri’s schema validation documentation.

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

Sidebar

Related Questions

I am trying to validate an XML document against an XML Schema . The
I am trying to validate an XML against schema using LibXML::Schema Validator CPAN module.
I'm trying to validate the following XML against a XSD schema using Ruby. It
I am trying to validate xml files against a very large industrial schema using
I'm trying to validate my XML document against my XML schema. This is my
I am trying to use dom4j to validate the xml at http://www.w3schools.com/Schema/schema_example.asp using the
I'm trying to validate an Xml fragment using an Xml Schema with the XDocument.Validate
I'm trying to develop a schema that will validate some existing XML files I've
I'm trying to write a schema that will validate the following XML: <category type=rifles>
I'm trying to write a xml schema that will validate this piece of xml:

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.