Skip to content

W3 validator throws error but g.parse() not #1712

Answered by ghost
Delilovic asked this question in Q&A
Discussion options

You must be logged in to vote

Do you know why rdflib does not throw an error message?

That's a reasonable question. RDFLib adopts the widely-accepted stance that a library is more useful to programmers if it is tolerant about what it accepts but strict about what it produces. In this instance, RDFLib is being useful, allowing us to work with the input.

Here's how it might go. Let's start by parsing the data:

>>> data = """<?xml version="1.0" encoding="UTF-8"?><root><child>OKOK</child></root>"""
>>> g = Graph()
>>> g.bind("ex", Namespace("urn:example:"))
>>> g.parse(data=data, format="xml")

As you observed, this does not produce an error and this is because the result of the parse is now something we can work with ...

Replies: 5 comments

Comment options

You must be logged in to vote
0 replies
Answer selected
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant
Converted from issue

This discussion was converted from issue #1708 on February 09, 2022 19:17.