开发者

How can I programmatically determine the XML elements that can be inserted next?

When I am editing an XML document that has an XmlSchema, how can I programmatically determine the elements that can be insert开发者_如何转开发ed next? I am using C# and I already know which element I am in. Is there an MSXML method I can call or something else? Thanks.


Sounds like you are after the .Net Schema Object Model (SOM)

Schema Object Model

Here is an article on how to work with the SOM.

Example 1


Tarzan,

As I understand it, you are trying to determine the legal XML that can be added at a specific place in the document, based on the schema being used. If that is correct, it is a very difficult problem to solve. If you have an "any" element in your XSD, your complexity increases because you can literally be any element! Also, XSD schemas can be subclassed (i.e., an element definition structure based on another structure), then that introduces more complexity. There are only couple of products (Oxygen, Visual Studio) that have attempted this with any success (that I know of).

If your schema is fairly simple, and doesn't include any of these deal breakers, you might be able to use the Schema Object Model to find the legal elements at your current location, but only if you know what portion of the XSD applies to your current element.

Does this make sense?

Erick

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜