-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support visitor pattern for tree mutation and multiple files #6
Comments
I'm considering forking xml_dart to:
|
Hah! Some reason I've not perused |
I've just committed 61ba675 that adds a simple node visitor to the library. The change cleans up other parts of the code as well, for example the (pretty) printing is now a visitor and separate to the node classes. The code also includes a transformation visitor that copies a tree and can be subclassed to perform custom transformations. I believe this allows a rather simple implementation of resolving imports. The currently committed code is work in progress. Let me know what you think. |
04d2629 makes the XmlParser event based, so that subclasses can transform the input while the source file is parsed. Again, the code is just experimental and work in progress. Let me know what you think. |
Okay. will do. I just made an xml_visitor so I have something to compare with. Thanks. |
Looks like in order to mutate a tree, I need to visit and copy. Very FP, but my visitors may be annotating, like adding new namespace elements and state. XmlElement ensures immutable. :-( @override
final List<XmlAttribute> attributes;
/**
* Create an [XmlElement] with the given `name`, `attributes`, and `children`.
*/
XmlElement(XmlName name, Iterable<XmlAttribute> attributes, Iterable<XmlNode> children)
: super(children),
name = name,
attributes = attributes.toList(growable: false) { |
|
Argh! The embedded SVG and dataURI are killing me... void main(){
group( "diagram", (){
test( "parse visit", (){
String xml = readFileTextSync("diagram_export_1.xml");
Stopwatch stopwatch = new Stopwatch()..start();
XmlDocument doc = parse(xml);
print( "parse time ${stopwatch.elapsed}");
stopwatch.reset();
DiaTransformer xform = new DiaTransformer();
DiaDoc dia = xform.visitDocument(doc);
print( "visit ${stopwatch.elapsed}");
});
});
}
|
Seems to work OK. Transformer has many visitIcon( XmlElement el ) => new Icon(el);
visitIcons( Iterable<XmlElement> icons ) => icons.map(visitIcon);
visitDia( XmlElement el ) => new Dia(el, visitIcons(el.findElements("Icon")) ); Have Transformer state variable passed in to constructor? DocState state;
visitIcon( XmlElement el ) => new Icon(el,state);
visitIcons( Iterable<XmlElement> icons ) => icons.map(visitIcon);
visitDia( XmlElement el ) => new Dia(el, visitIcons(el.findElements("Icon")), state ); |
I'll close this and just create a new issue if need be. |
I have an XSD that imports another XSD.
As package:xml exists, attributes, children etc are final and not mutable.
dart:html
DOM is mutable, which is useful for tree transformation.Ideally, the library could handle an import statement by one or more:
xs:import
node could have a childXmlDocument
, etc.The text was updated successfully, but these errors were encountered: