XML validation: 'No matching global declaration available for the validation root' error

Go To StackoverFlow.com

1

When I validate the following xml:

<?xml version="1.0" encoding="UTF-8"?>
<AvailRateUpdateRQ xmlns="http://www.expediaconnect.com/EQC/AR/2011/06"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="http://www.expediaconnect.com/EQC/AR/2011/06  ./XSD/AvailRateUpdateRQ.xsd">
  <Authentication username="user" password="ECLPASS"/>
  <Hotel id="111"/>
  <AvailRateUpdate>
    <DateRange from="2012-04-05" to="2012-04-07"/>
    <RoomType id="01">
      <Inventory totalInventoryAvailable="10"/>
      <RatePlan id="52ASD">
        <Rate currency="EUR">
          <PerDay rate="185.00"/>
        </Rate>
        <Restrictions minLOS="2" maxLOS="3" closedToArrival="true"/>
      </RatePlan>
    </RoomType>
  </AvailRateUpdate>
</AvailRateUpdateRQ>

using this schema:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 2011 Expedia, Inc. All Rights Reserved -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
  xmlns="http://www.expediaconnect.com/EQC/AR/2011/06" 
  targetNamespace="http://www.expediaconnect.com/EQC/AR/2011/06" 
  elementFormDefault="qualified" 
  attributeFormDefault="unqualified" 
  version="2.0.0">

  <xs:element name="AvailRateUpdateRQ">
      <xs:complexType>
         <!-- Definitions of some other element there -->
      </xs:complexType>
  </xs:element>

I get this error:

Error: 1845 Element 'AvailRateUpdateRQ': No matching global declaration available for the validation root.

2012-04-05 16:09
by ZigZag
Works for me - using Visual Studio 2010 for the validation. The xsi:schemaLocation in your XML file looks wrong - but maybe is just a typing problem - MiMo 2012-04-06 19:09


0

Really very funny.

$dom->loadXML($dom->saveXML) - this a part of code which help me in my problem.

2012-04-17 13:49
by ZigZag
There is at least one other similar report, apparently tied to the version of libXML: http://www.php.net/manual/en/domdocument.schemavalidate.php#89893 FWIW, I'm also seeing the same behavior - asmecher 2013-10-09 00:29
And I solved this using roughly the same solution as the top-voted answer above. Basiclly, you need to follow the instructions at http://php.net/manual/en/domdocument.createelementns.php to properly create an element with a namespace rather than setting the xmlns attribute yourself, which seems not to work. Whether that's a libxml bug or not is another question - asmecher 2013-10-09 00:47


4

I ran into a similar issue. Are you manually generating your XML? I was, and the problem was that while I added xmlns="Shema Info", that didn't actually set up the name space on the root node the same way as the parser does when reading in a file. So my generated root node wasn't in a name space, so it didn't match the root node in the validating schema.

I was using libxml2, so the calls were different. But when setting an xmlns attribute on a node, I instead did:

ns = xmlNewNs(par, val, NULL);
xmlSetNs(par, ns);

par is the parent, and val is the namespace url. I'm not sure if the par parameter is needed for the first call.

2012-09-26 21:48
by Bill S


0

Try using the \XMLReader for validation, instead of the \DOMDocument.

2018-11-13 11:16
by Mahmoud Zalt
Ads