0

I try to parse a MPD file with ElementTree

<?xml version="1.0" encoding="utf-8"?>
<MPD xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="urn:mpeg:dash:schema:mpd:2011"
    xmlns:xlink="http://www.w3.org/1999/xlink"
    xsi:schemaLocation="urn:mpeg:DASH:schema:MPD:2011 http://standards.iso.org/ittf/PubliclyAvailableStandards/MPEG-DASH_schema_files/DASH-MPD.xsd"
    profiles="urn:mpeg:dash:profile:isoff-live:2011"
    type="static"
    mediaPresentationDuration="PT12M14.1S"
    minBufferTime="PT16.0S">
    <ProgramInformation>
    </ProgramInformation>
    <Period id="0" start="PT0.0S">
        <AdaptationSet id="0" contentType="video" segmentAlignment="true" bitstreamSwitching="true">
            <Representation id="0" mimeType="video/mp4" codecs="avc1.640033" bandwidth="53739" width="4096" height="1714" frameRate="24/1">
                <SegmentTemplate timescale="12288" initialization="init-stream$RepresentationID$.mp4" media="chunk-stream$RepresentationID$-$Number%05d$.mp4" startNumber="1">
                    <SegmentTimeline>
import xml.etree.ElementTree as ET
tree = ET.parse(mpd_file[0])
        root = tree.getroot()
for node in tree.iter():
            if 'Representation' in node.tag:
                rep_node = node
                break
        print(rep_node.tag, rep_node.attrib)

Instead of just Representation it gives me:

('{urn:mpeg:dash:schema:mpd:2011}Representation', {'mimeType': 'video/mp4', 'width': '4096', 'bandwidth': '56271', 'codecs': 'avc1.640033', 'frameRate': '24/1', 'id': '0', 'height': '1714'})

Furthermore, I can not directly get all Nodes that have the tag Representation. I have to iterate through the whole tree.

user674907
  • 43
  • 2
  • 7
  • 1
    The “too much information” is the default namespace. See https://docs.python.org/3/library/xml.etree.elementtree.html#parsing-xml-with-namespaces – Daniel Haley Apr 04 '19 at 02:33
  • See https://stackoverflow.com/questions/13412496/python-elementtree-module-how-to-ignore-the-namespace-of-xml-files-to-locate-ma how to ignore namespace – balderman Apr 04 '19 at 08:22

0 Answers0