从创建XSD在.NET中的XML文件文件、XSD、NET、XML

2023-09-03 17:00:16 作者:恬淡

我想知道的最好的方法解决这个问题: 我想创建一个XML架构空白模板XML。所有必需的元素和属性将被创建,它们的值是所有空字符串。

I would like to know the best method for solving this problem: I would like to create a blank template xml from a xml schema. All the required elements and attributes would be created and their values would be all empty strings.

下一步是如何确定子XML节点某一节点可以有。例如。我会选择一个节点具有的minOccurs =0,maxOccurs为=无界为它的孩子中的一个。我能确定一切关于那个孩子,它的属性,它的名字,它的值类型,等等。

The next step is how to determine which child xml nodes a certain node could have. eg. I would select a node has has minOccurs="0", maxOccurs="unbounded" for one of its children. I would be able to determine everything about that child, its attributes, its name, its value type, etc.

要提供有关情况的详细背景下,我工作的一个工具,允许用户以更加人性化的设置编辑XML文件。对于例如,他们可以添加一个新帐户帐户数据库节点,他们会看到,唯一可用的节点是一个帐户节点。接下来,当他们试图给孩子添加到账号节点的选择将是名称节点(必填),密码节点(要求),设置节点(可选),等我如何通过编程方式确定哪些孩子的帐户节点都有可用它和哪些属性和设置都在那些孩子?

To give more context on the situation, I am working on a tool that allows users to edit xml files in a more user friendly setting. For eg, They could add a new account to the 'account db' node and they would see that the only available node is an account node. Next, when they try to add children to the account node and the choices would be name node (required), password node (required), settings node (optional), etc. How do I determine programmatically what children the account node has available to it and what the attributes and settings are on those children?

这是在C#2.0与.NET 2.0。

This is in C# 2.0 with .NET 2.0.

在总结,这班我用阅读的模式,并分析它来获得有用的信息,以便创建一个XML?在我幼稚我有希望,因为XSD是XML本身会有某种DOM模型的,我可以遍历。

In summary, which classes do I use to read a schema and parse it to get useful information for creating a xml? In my naivety I had hope that since xsd was xml in itself there would be some sort of DOM model that I could traverse through.

我想这仅限于我的程序,以便不使用外部工具,如OxygenXml,VS,XSD.EXE等。

I would like this to be confined to my program so no use of external tools such as OxygenXml, VS, xsd.exe, etc.

推荐答案

这听起来像你想要做的就是复制落后于最擅长的XML编辑器的XML智能感知的功能是什么。即读取XML架构,并制定出哪些元素和属性可以来下一个。

It sounds like what you want to do is replicated the functionality behind XML intellisense in most good XML Editors. ie read an xml schema and work out which elements and attributes can come next.

我们已经做了一些对我们以前工作过上一段时间的项目非常相似。要产生一些作品大部分时间是很多的工作,产品的一些作品所有的时间是工作负荷!

We have done something very similar on a project we worked on some time ago. To produce something that works most of the time is a lot of work, to product something that works all the time is loads of work!

基本上你需要加载的XSD(在.NET中的XmlSchema对象允许你这样做)。但他们暴露SOM对象模型是非常原始的,所以你需要做相当多的工作来除preT它。如果你忽略了像置换组,复杂类型的扩展,变色龙模式和namesapces概念,你应该能合理轻松地浏览SOM。

Basically you need to load the XSD (the XmlSchema objects in .net allow you to do this). But the SOM object model they expose is very raw, so you need to do quite a lot of work to interpret it. If you ignore concepts like substitution groups, complexType extension, chameleon schemas and namesapces, you should be able to navigate the SOM reasonably easily.

您接下来需要弄清楚您是否在XML文档中有关于您的架构。一旦你知是你在SOM你就可以开始工作了可用的选项。

You next need to figure out where you are in the XML document with relation to your schema. Once you known were you are in the SOM you can then start to work out the available options.

要做到这一点是正确的1,000 code和4-12人周工作线。你也许能够得到一些基本的东西一起在几个星期?

To do this properly is 1,000' of lines of code and 4-12 man weeks of work. You may be able to get something basic together in a few weeks?