Skip to content

Commit

Permalink
api ref: change XML example in open to use SAX
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgeorpinel committed Mar 8, 2020
1 parent 8bba8e8 commit 4a8111e
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions public/static/docs/api-reference/open.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,28 @@ using this API. For example, an XML file tracked in a public DVC repo on Github
can be processed directly in your Python app with:

```py
from xml.dom.minidom import parse
from xml.sax import parse
import dvc.api
from mymodule import mySAXHandler

with dvc.api.open(
'get-started/data.xml',
repo='https://github.com/iterative/dataset-registry'
) as fd:
xmldom = parse(fd)
# ... Process DOM
parse(fd, mySAXHandler)
```

> Notice that if you just need to load the complete file contents to memory, you
> can use `dvc.api.read()` instead:
Notice that we want to use a [SAX](http://www.saxproject.org/) XML parser here
because `dvc.api.open()` is able to stream the file, the `mySAXHandler` object
must handle the event-driven parsing of the document in this case.

> If you just need to load the complete file contents to memory, you can use
> `dvc.api.read()` instead:
>
> ```py
> from xml.dom.minidom import parse
> import dvc.api
>
> xmldata = dvc.api.read('get-started/data.xml',
> repo='https://github.com/iterative/dataset-registry')
> xmldom = parse(xmldata)
Expand Down

0 comments on commit 4a8111e

Please sign in to comment.