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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:42:20+00:00 2026-06-01T11:42:20+00:00

I have this XML of products which I’m trying to validate. (i keep it

  • 0

I have this XML of products which I’m trying to validate.

(i keep it in xml.xml file)

<?xml version="1.0" encoding="UTF-8"?>
<catalog label="global">
    <catalog label="animals" link="/animals.php">
    <subject>Subject1</subject>
     </catalog>
    <catalog label="animals" link="/animals.php">
    <subject>Subject2</subject>
     </catalog>
</catalog>

Generated XSD with this tool: (i put in file xml.xsd)

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="catalog" type="catalogType" />
  <xsd:complexType name="catalogType">
    <xsd:sequence>
      <xsd:element maxOccurs="unbounded" name="catalog" type="catalogType" />
    </xsd:sequence>
    <xsd:attribute name="label" type="xsd:string" />
  </xsd:complexType>
  <xsd:complexType name="catalogType">
    <xsd:sequence>
      <xsd:element name="subject" type="xsd:string" />
    </xsd:sequence>
    <xsd:attribute name="label" type="xsd:string" />
    <xsd:attribute name="link" type="xsd:string" />
  </xsd:complexType>
</xsd:schema>

And the PHP code which I use to test them (in php.php file):

<?php 

function libxml_display_error($error) 
{ 
  $return = "<br/>\n"; 
  switch ($error->level) { 
  case LIBXML_ERR_WARNING: 
  $return .= "<b>Warning $error->code</b>: "; 
  break; 
  case LIBXML_ERR_ERROR: 
  $return .= "<b>Error $error->code</b>: "; 
  break; 
  case LIBXML_ERR_FATAL: 
  $return .= "<b>Fatal Error $error->code</b>: "; 
  break; 
  } 
  $return .= trim($error->message); 
  if ($error->file) { 
  $return .= " in <b>$error->file</b>"; 
  } 
  $return .= " on line <b>$error->line</b>\n"; 

  return $return; 
} 

    function checkXMLStructure($xml_object)
    {
        $xmlElement = $xml_object->catalog;
        $dom_sxe = dom_import_simplexml($xmlElement);

        $dom = new DOMDocument('1.0');
        $dom_sxe = $dom->importNode($dom_sxe, true);
        $dom_sxe = $dom->appendChild($dom_sxe);

        if ( !$dom->schemaValidate( dirname(__FILE__) . '/xml.xsd') ) {
            echo "BAD XML\n";
        return;
        }

        echo "*GOOD* XML!\n";
    }

// Enable user error handling 
libxml_use_internal_errors(true);

$xml_object = simplexml_load_file('xml.xml');
checkXMLStructure($xml_object);

// Display Errors
$errors = libxml_get_errors(); 
foreach ($errors as $error) { 
print libxml_display_error($error); 
} 
libxml_clear_errors();

The output:

PHP Warning:  DOMDocument::schemaValidate(): Element '{http://www.w3.org/2001/XMLSchema}complexType': A global complex type definition 'catalogType' does already exist. in /path/php.php on line 13
PHP Stack trace:
PHP   1. {main}() /path/php.php:0
PHP   2. checkXMLStructure() /path/php.php:23
PHP   3. DOMDocument->schemaValidate() /path/php.php:13
PHP Warning:  DOMDocument::schemaValidate(): Invalid Schema in /path/php.php on line 13
PHP Stack trace:
PHP   1. {main}() /path/php.php:0
PHP   2. checkXMLStructure() /path/php.php:23
PHP   3. DOMDocument->schemaValidate() /path/php.php:13
BAD XML

I need to rewrite the schema such that it will notice the *many elements inside the main element (please note the same name usage).

  • 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-01T11:42:21+00:00Added an answer on June 1, 2026 at 11:42 am

    I’ve used QTAssistant to generate the schema below (which validates the XML you have provided):

    <?xml version="1.0" encoding="utf-8"?>
    <!--W3C Schema generated by QTAssistant/W3C Schema Refactoring Module (http://www.paschidev.com)-->
    <xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <xsd:element name="catalog">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element maxOccurs="unbounded" name="catalog">
              <xsd:complexType>
                <xsd:sequence>
                  <xsd:element name="subject" type="xsd:string" />
                </xsd:sequence>
                <xsd:attribute name="label" type="xsd:string" use="required" />
                <xsd:attribute name="link" type="xsd:string" use="required" />
              </xsd:complexType>
            </xsd:element>
          </xsd:sequence>
          <xsd:attribute name="label" type="xsd:string" use="required" />
        </xsd:complexType>
      </xsd:element>
    </xsd:schema>
    

    You could start from the above and tweak it as you go along.

    Validation results:

    Validation results

    If you wish to manually fix the XSD your tool created, then make sure that you rename only the first two occurrences of the catalogType to something else (e.g. catalogType1).

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

Sidebar

Related Questions

I have this xml file <?xml version=1.0 encoding=UTF-8?> <bo:C837ClaimParent xsi:type=bo:C837ClaimParent xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:bo=http://somelongpathHere/process/bo> <claimAux> ...
I have this XML : <?xml version=1.0 encoding=utf-8 ?> <IMPORT mode=FULL> .... </IMPORT> I'm
I have this XML: <?xml version=1.0 encoding=utf-8?> <ConfiguraCanale ID_Comando=1> <canaleDigitalOUTPUT ID_Canale=1 > <stato>0</stato> </canaleDigitalOUTPUT>
I have this xml from which I am trying to grab the value in
I have this xml file which has text init. i.e Hi my name is
I have this xml <products> <product> <name>Demo</name> </product> <product> <name>Black Beauty III</name> <description>Beautiful les
I have an XML file with the following structure: <Products> <Product name=MyProduct1> <Components> <Component
Suppose I have xml like this: <Products> <Product name=Liquid Oxygen> <Manufacturer name=Universal Exports country=UK
I have a csv file which I want to convert to xml but the
I have this xml <KitContent> <MsiData> <FileName>file1</FileName> <BaseProductVersion>1.1.0.0</BaseProductVersion> </MsiData> <MsiData> <FileName>file2</FileName> <BaseProductVersion>1.1.0.0</BaseProductVersion> </MsiData> </KitContent>

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.