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

时间:2022-02-05 18:18:30

When I am editing an XML document that has an XmlSchema, how can I programmatically determine the elements that can be inserted 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.

当我编辑具有XmlSchema的XML文档时,如何以编程方式确定下一个可插入的元素?我正在使用C#,我已经知道我在哪个元素。是否有可以调用的MSXML方法或其他东西?谢谢。

2 个解决方案

#1


1  

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

#2


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

据我了解,您正在尝试根据所使用的架构确定可以在文档中的特定位置添加的合法XML。如果这是正确的,那么解决这个问题非常困难。如果你的XSD中有一个“any”元素,你的复杂性会增加,因为你可以真正地成为任何元素!此外,XSD模式可以是子类(即,基于另一种结构的元素定义结构),然后引入更多复杂性。只有几种产品(氧气,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

埃里克

#1


1  

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

#2


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

据我了解,您正在尝试根据所使用的架构确定可以在文档中的特定位置添加的合法XML。如果这是正确的,那么解决这个问题非常困难。如果你的XSD中有一个“any”元素,你的复杂性会增加,因为你可以真正地成为任何元素!此外,XSD模式可以是子类(即,基于另一种结构的元素定义结构),然后引入更多复杂性。只有几种产品(氧气,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

埃里克