开发者

How to Validate an XML Node against an XSD in C++?

开发者 https://www.devze.com 2023-01-03 13:58 出处:网络
Please note that I\'m asking for validation against a particular node and not the whole file. For examples

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

<somexmldoc>
    <someNode>
        <UserDefined开发者_JAVA技巧Node> </>
        <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!


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.


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.


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 :-)

0

精彩评论

暂无评论...
验证码 换一张
取 消