Q:

XML Schema that allows anything (xsd:any)

I need an example of XML schema that will allow anything and everything.
It might sound weird like this, but I need that to debug my current schema. The thing is that I have a complex object that I use in a function (part of a DLL I have no control over) along with a schema, and that functions returns me the XML. For now the function throws an exception because there's an error while validating with the schema, but there shouldn't be one. So, I want a blank schema, a schema that will not cause any validation error, so I can see the XML outputted by the function.
I tried to take my current schema, and keep only the xs:schema tag to create an empty schema, but that obviously didn't work.

A:

XML Schema cannot specify that a document is valid regardless of its content.
However, if you're able to specify the root element, you can use xs:anyAttribute and xs:any to allow any attributes on the root element and any XML under the root:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="root">
    <xs:complexType>
      <xs:sequence>
        <xs:any processContents="skip" minOccurs="0" maxOccurs="unbounded"/>
      </xs:sequence>
      <xs:anyAttribute processContents="skip"/>
    </xs:complexType>
  </xs:element>
</xs:schema>

In your case, as long as you can be assured of a finite number of possible root element names, you can use this technique to allow any XML content under a root element with a known name.

Update: This can be written much more concisely [Credit: C. M. Sperberg-McQueen]:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="root"/>
</xs:schema>

Note that this is allowing, but not requiring, root to be empty.

A:

It's often assumed that an XML schema partitions documents into those that are valid and those that are not. It's actually rather more subtle than that. When you invoke validation, you need to say how you want the validation done. The most common invocation is strict validation, in which case either the name of the root element in your instance document must correspond to the name of a global element declaration in your schema, or it must have an xsi:type attribute that matches a global type definition in your schema. It follows that no finite schema will match every document instance under strict validation.
In principle you can also invoke a schema processor to do lax validation. In this case, if there is no match for the root element name among the global element declarations in the schema, validation succeeds. So the empty schema (no declarations) matches every instance document under lax validation.
You can also invoke validation against a named type. If you invoke validation against the named type xs:anyType, then every instance is valid, regardless what the schema says.
Caveat: I've considerably simplified the rules here.

