Skip to content
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

Example of dropping a field while parsing #613

Closed
danvk opened this issue Apr 22, 2016 · 1 comment
Closed

Example of dropping a field while parsing #613

danvk opened this issue Apr 22, 2016 · 1 comment
Labels

Comments

@danvk
Copy link
Contributor

danvk commented Apr 22, 2016

See this StackOverflow question. I'm parsing large GeoJSON files and would like to produce Document objects without the coordinates arrays, which can easily take up 75+% of the space.

I implemented a GenericValue subclass which uses the SAX parser callbacks and its own stack to pull this off. It winds up roughly doubling parsing performance, so this is a very worthwhile optimization. It leaves much to be desired, however: it duplicates large amounts of code from GenericDocument and it's unable to build up objects in exactly the same manner, since methods like GenericValue::SetObjectRaw are private.

@miloyip suggested on StackOverflow that a better way to do this would be with the GenericDocument::Populate method, and that I should file an issue asking for an example. So here I am :)

@miloyip
Copy link
Collaborator

miloyip commented Apr 23, 2016

Hi,

I have created two examples in #615. Both examples do the same thing, they filter a user-specified key, and then output the filtered results. filterkey just uses SAX API, while filterkeydom firstly populates a DOM, and then output the DOM.

Its usage is like this:

widget.json

{"widget": {
    "debug": "on",
    "window": {
        "title": "Sample Konfabulator Widget",
        "name": "main_window",
        "width": 500,
        "height": 500
    },
    "image": { 
        "src": "Images/Sun.png",
        "name": "sun1",
        "hOffset": 250,
        "vOffset": 250,
        "alignment": "center"
    },
    "text": {
        "data": "Click Here",
        "size": 36,
        "style": "bold",
        "name": "text1",
        "hOffset": 250,
        "vOffset": 100,
        "alignment": "center",
        "onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
    }
}}
$ filterkey image < widget.json | pretty
{
    "widget": {
        "debug": "on",
        "window": {
            "title": "Sample Konfabulator Widget",
            "name": "main_window",
            "width": 500,
            "height": 500
        },
        "text": {
            "data": "Click Here",
            "size": 36,
            "style": "bold",
            "name": "text1",
            "hOffset": 250,
            "vOffset": 100,
            "alignment": "center",
            "onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
        }
    }
}

The core thing is the FilterKeyHandler, which receives SAX events, filters them, and forward to the output handler. Both examples uses the same FilterKeyHandler. I think you may implement your own filter for your requirements.

@miloyip miloyip closed this as completed Dec 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants