views:

108

answers:

4

Hi

Please note that I'm asking for validation against a particular node and not the whole file. For examples

<somexmldoc>
    <someNode>
        <UserDefinedNode> </>
        <UserDefinedNode> </>
    </someNode>
</somexmldoc>

For this XML doc, I have an wholeDoc.XSD which could be used to validate the whole document except "UserDefinedNode" (This node is specified with "any" tag in xsd, which allows a user to define anything under that node).

Is it possible to have a separate userdefined.XSD file to validate "UserDefinedNode"? Is it possible to use MSXML for C++ (IXMLDomDocument) to validate this?

Thanks!

A: 

Yes that is possible. I would recommend to download Microsoft Core XML Services (MSXML) 6.0 SDK as it has a C++ sample code that shows how to do that.

volody
A: 

Should be possible. I found a document called HOW TO: Validate XML Fragments Against an XML Schema in Visual C#.NET for you (see here). That's C#, but you should be able to translate this :-)

mkluwe
A: 

XSD applies to the whole DOM document but not DOM fragment. However, as your fragment is also valid XML, why not copy it to another DOM object as the root? You can leverage appendChild or cloneNode to achive this and then validate the new DOM.

By the way, if you want to validate a specified DOM fragment, validateNode method is there for you.

Samuel Zhang