重构 .xsd 架构的工具?
我得到了一个 .xsd 方案,它具有多个根元素,很少有复杂和简单类型,复杂类型引用这些根元素。由于这些根元素,我无法以我想要的方式生成 .xml。所以我认为我需要添加将作为根元素的元素,并将所有其他元素添加为其子元素,还是我错了?
有没有一个工具可以帮助我创建根元素和重构方案?我得到了什么:
我在想也许我只需要创建另一个带有 1 个元素的 xsd 并引用第一个 xsd 中的所有元素它,但我不完全知道该怎么做。这是个好主意吗?
I got an .xsd scheme that has multiple root elements, few complex and simple types, complex types refer to those root elements. I can't generate .xml in a way i want from it because of those root elements. So i think i need to add element that will serve as the root element, and add all other elements as its children, or am i wrong?
Is there a tool that can help me create root element and refactor scheme? What i got:
I was thinking maybe i just need to create another xsd with 1 element and ref all elements form first xsd in it, but i don't exactly know how to do it. Is this a good idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如 Pangea 所说,您编辑的答案确实是“不”。这是因为要引用另一个元素(如),引用的元素必须全局声明。
需要全局元素的其他场景是使用替换组。我试图建议的是,重构 XSD 的方式可能并不总是能够仅将您想要作为实例 XML 中的根的元素保留为全局。
这应该让您认为要解决您的问题,更好的方法可能是找出无法按照您想要的方式生成 .xml 的原因。如果您可以描述其中的一些内容,您可能会在这里得到更好的答案...
我想添加此答案的另一个原因是我注意到使用 XML 作为标签名称。虽然看起来不错,但我可以告诉您,我见过一些相当“大牌”的应用程序,它们只会因而感到窒息。标签名称。 XML实际上是“保留的”,请看一下本节。引用:“名称以字符串“xml”开头,或以任何匹配的字符串 (('X'|'x') ('M'|'m') ('L'|'l') )),保留用于本规范的当前版本或未来版本中的标准化。“
始终遵守规范......
The answer to your edit is indeed, as Pangea said, NO. And that is because to ref another element (as in <xsd:element ref="SomeElement" ... />), the referenced element must be declared globally.
Other scenario that requires global elements is the use of substitution groups. What I am trying to suggest is that it may not always be possible to refactor an XSD in a way that leaves global only the elements you want as root in instance XML.
Which should make you think that to solve your problem, a better way might be to go after the reason why you can't generate .xml the way you want. If you can describe a bit of that, you might get a better answer here...
Another reason I wanted to add this answer was that I noticed the use of XML as a tag name. While it may seem OK, I can tell you that I've seen some pretty "big-name" applications that would simply choke with that <XML/> tag name. XML is actually "reserved", please take a look at this section of the XML Spec. To quote: "Names beginning with the string "xml", or with any string which would match (('X'|'x') ('M'|'m') ('L'|'l')), are reserved for standardization in this or future versions of this specification."
Always play nice with the specs....
您在架构中定义的任何全局元素都是实例文档中的潜在根元素。如果您不希望出现这种行为,请确保您在 xsd 中只有一个全局元素定义。它与工具无关(尽管 xml 编辑器可以简化这一点)。
Any global element you define in the schema is a potential root element in the the instance document. If you doesn't want this behavior then make sure you have only one global element definition in the xsd. It has nothing to do with the tool (though xml editors can simplify this).