gpt4 book ai didi

java - 如何从相应的 xsd'S 获取自己的 xml 编辑器的信息?

转载 作者:行者123 更新时间:2023-12-02 09:22:29 24 4
gpt4 key购买 nike

我想用 java 编写一个 xml 编辑器,并希望获取 xml 元素的信息,例如可能的子元素、使用相应 xsd 的文档。为了进行验证,我可以使用这个简单的代码片段,但我认为它不能帮助我获取 xml 中某个特定元素的信息:

 StreamSource[] schemaDocuments = { new StreamSource("layout.xsd") };
/* created by your application */;
Source instanceDocument = new StreamSource("BEW.xml");
/* created by your application */;

SchemaFactory sf = SchemaFactory.newInstance(
"http://www.w3.org/2001/XMLSchema");
Schema s = sf.newSchema(schemaDocuments);

Validator v = s.newValidator();

v.validate(instanceDocument);

最佳答案

EMF 项目是一个建模框架和代码生成工具,用于构建基于结构化数据模型的工具和其他应用程序。

https://www.eclipse.org/modeling/emf/

参见http://blog.xequtor.com/post/2017/06/12/emf-create-ecore-model-from-xsd-file示例项目。

我已经看到它非常成功地用于为各种复杂的数据模型生成编辑器,并且我已经编写了代码来加载 XSD 并使用 EMF 迭代其内容。它对 XSD 标准的实现非常彻底 - 它将加载 xs:includes 和 xs:imports 并将根据 W3C 规范中的规则验证 XSD。

关于java - 如何从相应的 xsd'S 获取自己的 xml 编辑器的信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58591311/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com