Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

xml

xsd

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.

like image 743
Tarzan Avatar asked Nov 06 '22 07:11

Tarzan


2 Answers

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

like image 67
Leigh S Avatar answered Nov 09 '22 10:11

Leigh S


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

like image 33
Erick T Avatar answered Nov 09 '22 08:11

Erick T