Posted 13 years ago by kai zhang
Version: 11.1.0110
Avatar
We are trying to parse Xml using the out of box XmlParser. And we want to add some extra parsing rules such as

Xml Element cannot have duplicated attributes (e.g. <Element Name="blah" Name="blah"/> needs to raise a parsing error "Duplicate 'Name' attribute").

Is it possible to extend the out-of-box XmlParser to support this parsing rule? If possible, where should I start? Thanks.

Comments (3)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Kai,

The easiest way to do this would probably be to create a class that inherits XmlParser and register that as the IParser service on your XmlSyntaxLanguage in place of the default one.

Then override the Validate method on it and recursively examine AST nodes in the AST data (from the state.AstNodeBuilder.RootNode parameter) to look for duplicate attribute names. You can update the state.ParseErrors collection if you find validation errors.


Actipro Software Support

Posted 13 years ago by kai zhang
Avatar
Thanks for your hint. Follow your suggestion, I created a CustomXmlParser that inherits XmlParser and that part is working now:)

The next thing I want to do is to introduce a CustomXmlParseData which naturally inherits XmlParseData, and let the CustomXmlPaser's base class, XmlParser, to use it.

However I couldn't figure out a way to let the XmlParser to use the CustomXmlParseData instead of XmlParseData.

Is it do-able? any hint on that?

Thanks
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Kai,

You can override the CreateParseData method, call its base to get the default IXmlParseData result, then just copy all its properties to your own CustomXmlParseData class, and return that.


Actipro Software Support

The latest build of this product (v18.1 build 0233) was released 4 years ago, which was after the last post in this thread.