0

在java中,我想要一个dtd文件中元素的属性列表。

DTD 示例:

<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>

我需要类似getChilds(note)...

有可能这样做吗?我需要一个 dtd 解析器,但我找不到提供这个的解析器。

谢谢!

4

1 回答 1

0

You may use a SAX parser, with a DeclHandler.

To set the DeclHandler for an XML reader, use the setProperty method with the property name http://xml.org/sax/properties/declaration-handler and an object implementing DeclHandler. If the reader does not report declaration events, it will throw a SAXNotRecognizedException when you attempt to register the handler.

The model argument in method DeclHandler.elementDecl(String name, String model) for name="note" would be (to,from,heading,body).

于 2013-03-19T14:35:47.103 回答