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

ElementTree won't parse comments before root element #82923

Closed
celinecyc mannequin opened this issue Nov 8, 2019 · 2 comments
Closed

ElementTree won't parse comments before root element #82923

celinecyc mannequin opened this issue Nov 8, 2019 · 2 comments
Labels
topic-XML type-feature A feature request or enhancement

Comments

@celinecyc
Copy link
Mannequin

celinecyc mannequin commented Nov 8, 2019

BPO 38742
Nosy @amauryfa, @scoder, @florentx, @celinecyc
Superseder
  • bpo-9521: xml.etree.ElementTree skips processing instructions when parsing
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2019-11-15.17:41:44.927>
    created_at = <Date 2019-11-08.08:10:53.518>
    labels = ['expert-XML', 'type-feature']
    title = "ElementTree won't parse comments before root element"
    updated_at = <Date 2019-11-15.17:41:44.926>
    user = 'https://github.com/celinecyc'

    bugs.python.org fields:

    activity = <Date 2019-11-15.17:41:44.926>
    actor = 'scoder'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-11-15.17:41:44.927>
    closer = 'scoder'
    components = ['XML']
    creation = <Date 2019-11-08.08:10:53.518>
    creator = 'celinecyc'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 38742
    keywords = []
    message_count = 2.0
    messages = ['356229', '356698']
    nosy_count = 6.0
    nosy_names = ['effbot', 'amaury.forgeotdarc', 'scoder', 'poke', 'flox', 'celinecyc']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '9521'
    type = 'enhancement'
    url = 'https://bugs.python.org/issue38742'
    versions = ['Python 3.6']

    @celinecyc
    Copy link
    Mannequin Author

    celinecyc mannequin commented Nov 8, 2019

    bpo-8277
    It couldn't work for those comments before the root element.
    It will raise an error that "xml.etree.ElementTree.ParseError: multiple elements on top level".

    Example:

    test.xml
    --------
    <?xml version="1.0" encoding="utf-8"?>
    <!-- comments here doesn't work -->
    <root node>
    <nodeA />
    <!-- comments here is ok -->
    <nodeB />
    </root node>

    test.py
    -------

    from xml.etree import ElementTree
    class MyTreeBuilder(ElementTree.TreeBuilder):
       def comment(self, data):
           self.start(ElementTree.Comment, {})
           self.data(data)
           self.end(ElementTree.Comment)
    with open('c:/temp/t.xml', 'r') as f:
       xml = ElementTree.parse(
           f, parser=ElementTree.XMLParser(target=MyTreeBuilder()))
    ElementTree.dump(xml)

    @celinecyc celinecyc mannequin added topic-XML type-feature A feature request or enhancement labels Nov 8, 2019
    @scoder
    Copy link
    Contributor

    scoder commented Nov 15, 2019

    Duplicate of bpo-9521 (and bpo-24287).

    @scoder scoder closed this as completed Nov 15, 2019
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    topic-XML type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant