简体   繁体   English

如何从XSD提取标签名称?

[英]How to extract tag names from an XSD?

I need to write in Java. 我需要用Java编写。 Is there any sample code available in this regard? 在这方面是否有任何示例代码?

You could use Apache XmlSchema library ( http://ws.apache.org/commons/xmlschema14 ). 您可以使用Apache XmlSchema库( http://ws.apache.org/commons/xmlschema14 )。

The idea is to create the instance of XmlSchema class that represents your schema: 这个想法是创建代表您的模式的XmlSchema类的实例:

InputStream is = new FileInputStream(fileName);
XmlSchemaCollection schemaCol = new XmlSchemaCollection();
XmlSchema schema = schemaCol.read(new StreamSource(is), null);

and use it to obtain information about elements and types specified by your schema. 并使用它来获取有关架构指定的元素和类型的信息。 You could for instance enlist all element names: 例如,您可以注册所有元素名称:

XmlSchemaObjectTable objTable = schema.getElements();
Iterator elementNames = objTable.getNames();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM