How to add a root to an XML file?

42 views Asked by At

I have an xml file in the following format:

<event time="0.0" type="actend" person="770885_2_Person" link="271711" actType="other"  />
    <event time="0.0" type="departure" person="770885_2_Person" link="271711" legMode="car"  />
    <event time="0.0" type="PersonEntersVehicle" person="770885_2_Person" vehicle="770885_2_Person"  />
    <event time="0.0" type="vehicle enters traffic" person="770885_2_Person" link="271711" vehicle="770885_2_Person" networkMode="car" relativePosition="1.0"  />
    <event time="1.0" type="left link" link="271711"  />
    <event time="1.0" type="entered link" link="271715" vehicle="770885_2_Person"  />
    <event time="15.0" type="left link" link="271715"  />
    <event time="15.0" type="entered link" link="535413" vehicle="770885_2_Person"  />
    <event time="17.0" type="left link" link="535413"  />
    <event time="17.0" type="entered link" link="813064" vehicle="770885_2_Person"  />
    <event time="19.0" type="left link" link="813064"  />
    <event time="19.0" type="entered link" link="813066" vehicle="770885_2_Person"  />
    <event time="22.0" type="left link" link="813066"  />
    <event time="22.0" type="entered link" link="813068" vehicle="770885_2_Person"  />
    <event time="23.0" type="actend" person="368018_2_Person" link="614790" actType="other"  />
    <event time="23.0" type="departure" person="368018_2_Person" link="614790" legMode="car"  />
    <event time="23.0" type="PersonEntersVehicle" person="368018_2_Person" vehicle="368018_2_Person"  />
    <event time="23.0" type="vehicle enters traffic" person="368018_2_Person" link="614790" vehicle="368018_2_Person" networkMode="car" relativePosition="1.0"  />
    <event time="24.0" type="left link" link="614790"  />
....

A root node is missing, thus, when I do treeEvents = et.parse(file_occup_xml) I get error related to the absence of the root (when I add a root manually the above parse works fine). So i looked here and here, however, in both cases I cannot actually do the parse() command since there is no root.

Do I miss something here? How can I then add a root on that XML file?

0

There are 0 answers