简体   繁体   English

如何以编程方式确定下一步可插入的XML元素?

[英]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 inserted next? 当我编辑具有XmlSchema的XML文档时,如何以编程方式确定下一个可插入的元素? I am using C# and I already know which element I am in. Is there an MSXML method I can call or something else? 我正在使用C#,我已经知道我在哪个元素。是否有我可以调用的MSXML方法或其他东西? Thanks. 谢谢。

Sounds like you are after the .Net Schema Object Model (SOM) 听起来像是在.Net模式对象模型(SOM)之后

Schema Object Model 模式对象模型

Here is an article on how to work with the SOM. 这是一篇关于如何使用SOM的文章。

Example 1 例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. 据我了解,您正在尝试根据所使用的架构确定可以在文档中的特定位置添加的合法XML。 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! 如果你的XSD中有一个“any”元素,你的复杂性就会增加,因为你可以真正地成为任何元素! Also, XSD schemas can be subclassed (ie, an element definition structure based on another structure), then that introduces more complexity. 此外,XSD模式可以是子类(即,基于另一个结构的元素定义结构),然后引入更多的复杂性。 There are only couple of products (Oxygen, Visual Studio) that have attempted this with any success (that I know of). 只有几种产品(氧气,Visual Studio)试图取得任何成功(我知道)。

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. 如果您的架构非常简单,并且不包含任何这些交易破坏者,您可以使用架构对象模型在当前位置查找合法元素,但前提是您知道XSD的哪个部分适用于你当前的元素。

Does this make sense? 这有意义吗?

Erick 埃里克

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM