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 the following problem: I have 2 XML documents, both generated by different source systems and while both will, for example, have elements ABC, they also will have unremovable elements generated by the source system.

My question is: can I use a single schema to validate two slightly different XML files?

For example:

Doc1:

<gibberish/>
<system_specific_nonsense/>
<A>
    <uselessblock>
        <B>
            <ID/>
            <name/>
        </B>
    </uselessblock>
</A>

Doc2

<stuff/>
<gobbletygook/>
<lalalalalalalal/>
<A>
    <B>
        <ID/>
        <name/>
    </B>
</A>

Is there a way to have a schema that only vaguely says:

<A>
    <B>
        <ID/>
        <name/>
    </B>
</A>

In other words, a schema that ignores hierarchy depth and unrecognized elements, only vaguely saying "It must have an A, and somewhere in that A is a B, and somewhere in that B is an ID and a name".

Is this even remotely possible? If not, are there any workarounds I might look into?

Background info: I'm taking nightly data from a source system and a slave system. I compare the source to the slave to see what is different between the two and then pushing the change-only data to the slave system. In order to facilitate this, I want any data extracted from either system run through the vague validation because my comparison code is vague enough to ignore hierarchy depth.

Thanks.

share|improve this question
    
Sorry if this is a silly question, but do you know when the unrecognised elements may appear? If you do then you might be able to specify these as optional in your schema. –  Jay Jan 29 at 21:11
    
@Jay I do, but the problem is that I want a single schema to cover both files. Or is this what you're implying? I could mush both into a single schema and mark them all as optional, but then I'd need a way to say I need either optional element A which looks like this, or optional element A which looks like this, etc. –  Tor Jan 29 at 21:13
    
No the rubbish should not be changing. However, one of the systems, for example, has an array of <employee> elements in an <employeeList> root, while the other must spit out these <employee>s each wrapped in an <employeeBlock> within the <employeeList>. Would you be putting both into your schema? How do I specify that one of the two types must be present? "Choice"? –  Tor Jan 29 at 21:18
    
Yes I was implying using a series of choice elements - sorry - I don't know of any other way to achieve your goal! Good luck! –  Jay Jan 29 at 21:18
1  
@Tor If scheme of both is known, validate them individually, if validation is all you want to achieve. –  milter Jan 29 at 23:07
show 2 more comments

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.