Validate against schema, but ignore the rest

A

Andy

Hello All!

Is there any way to validate XML document agains schema, but at the
same time ignore any attributes or elements that are not specified in
schema?

Example:
<Customer>
<LastName></LastName>
<FirstName></FirstName>
<Age></Age>
<AnyNode/>
</Customer >

Assume that schema only define LastName, and FirstName.
How can Age be ignored without knowing that it is Age?
How can AnyNode be ignored?

Thank you
 
M

Martin Honnen

Andy wrote:

Is there any way to validate XML document agains schema, but at the
same time ignore any attributes or elements that are not specified in
schema?

Example:
<Customer>
<LastName></LastName>
<FirstName></FirstName>
<Age></Age>
<AnyNode/>
</Customer >

Assume that schema only define LastName, and FirstName.
How can Age be ignored without knowing that it is Age?
How can AnyNode be ignored?

Here is a schema that specifies that <Customer> is a sequence of
<LastName>, <FirstName> and an unspecified number of elements that are
skipped during validation:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="Customer">
<xs:complexType>
<xs:sequence>
<xs:element name="LastName" type="xs:string" />
<xs:element name="FirstName" type="xs:string" />
<xs:any processContents="skip" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top