consider this:
I'm inside a (selfbuilt) XML Editor and am about to add a Child to an XmlNode开发者_开发技巧. How do I know which types of children are valid according to a DTD.
it's a behaviour like Intellisense. I couldn't find any .NET classes for "parsing" the DTD.
How would i go about this?
Unfortunately, the DOM Level 1 Core standard which XmlDocument
implements does not provide any access to <!ELEMENT>
and <!ATTLIST>
declarations in a DTD (internal subset or, if configured to read it, external DTD).
You do get Document.DocumentType.Entities
, which tells you what general entities (&something;
) were defined in the DTD, and Notations
, which is largely useless, but not Elements
or Attlists
. Whilst there exist DOMs that will retain this information, I'm not aware of any for .NET (unless you want to go running pxdom through IronPython, which would probably be a bit of a pain and not at all fast) and nothing that integrates with System.Xml
.
You could possibly hook up saxdotnet, using a declHandler (looks like eg. ExpatReader.SetDeclHandlerForParsing in saxdotnet) to pick up these declarations. Either as a separate parse process for the internalSubset/systemId DTD, or as a replacement for .NET's own parsing, converting the event stream in an XmlDocument manually.
精彩评论