Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have two xml files as below.

I want to check the attribute Id should have same value in both xml files.

Can I do it suing XSD ?

<!-- Library.xml -->

<?xml version="1.0" encoding="utf-8"?>
<Library>
  <Book Id="1"/>
</Library>

 <!-- ######################################## -->

<!-- Book.xml -->
<?xml version="1.0" encoding="utf-8"?>
<Books>
  <XmlBook Id="1"/>
</Books>

Id attribute value for XmlBook and Book should be always same. Can I check or validate it using XSD or Can I put restriction using XSD for this values ?

Thanks in Adavnce

Regards,

Ani

share|improve this question

1 Answer 1

XSD is designed to validate individual nodes, typically single documents; cross-document validation is not built in to XSD.

You might use a different schema language (Schematron and SML are the two that come to mind) to express and check your cross-document constraints.

Or you might check the cross-document constraints by using XInclude to make a single document with both of your source documents as parts, and then use paired key and keyref constraints to ensure that every Id value in the one part of the compound document matches an Id value in the other part, and vice versa.

share|improve this answer
    
Key and KeyRef is not working , because it need Xpath , How can I give Xpath for Attributes of included XSD ? –  user3652040 May 21 at 9:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.