1

Similar to this question I want to obtain a dataframe from an XML files. Here is my XML file and it is in the file "1.xml".

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE us-patent-application SYSTEM "us-patent-application-v44-2014-04-03.dtd" [ ]>
<us-patent-application lang="EN" dtd-version="v4.4 2014-04-03" file="US20200262283A1-20200820.XML" status="PRODUCTION" id="us-patent-application" country="US" date-produced="20200805" date-publ="20200820">
<us-bibliographic-data-application lang="EN" country="US">
<publication-reference>
<document-id>
<country>US</country>
<doc-number>20200262283</doc-number>
<kind>A1</kind>
<date>20200820</date>
</document-id>
</publication-reference>
<application-reference appl-type="utility">
<document-id>
<country>US</country>
<doc-number>16817919</doc-number>
<date>20200313</date>
</document-id>
</application-reference>
<us-application-series-code>16</us-application-series-code>
<classifications-ipcr>
<classification-ipcr>
<ipc-version-indicator><date>20060101</date></ipc-version-indicator>
<classification-level>A</classification-level>
<section>B</section>
<class>60</class>
<subclass>J</subclass>
<main-group>11</main-group>
<subgroup>04</subgroup>
<symbol-position>F</symbol-position>
<classification-value>I</classification-value>
<action-date><date>20200820</date></action-date>
<generating-office><country>US</country></generating-office>
<classification-status>B</classification-status>
<classification-data-source>H</classification-data-source>
</classification-ipcr>
</classifications-ipcr>
<classifications-cpc>
<main-cpc>
<classification-cpc>
<cpc-version-indicator><date>20130101</date></cpc-version-indicator>
<section>B</section>
<class>60</class>
<subclass>J</subclass>
<main-group>11</main-group>
<subgroup>04</subgroup>
<symbol-position>F</symbol-position>
<classification-value>I</classification-value>
<action-date><date>20200820</date></action-date>
<generating-office><country>US</country></generating-office>
<classification-status>B</classification-status>
<classification-data-source>H</classification-data-source>
<scheme-origination-code>C</scheme-origination-code>
</classification-cpc>
</main-cpc>
</classifications-cpc>
<invention-title id="d2e43">VEHICLE ROOF-MOUNTED SHADING APPARATUS</invention-title>
<us-related-documents>
<continuation>
<relation>
<parent-doc>
<document-id>
<country>US</country>
<doc-number>15598363</doc-number>
<date>20170518</date>
</document-id>
<parent-grant-document>
<document-id>
<country>US</country>
<doc-number>10625588</doc-number>
</document-id>
</parent-grant-document>
</parent-doc>
<child-doc>
<document-id>
<country>US</country>
<doc-number>16817919</doc-number>
</document-id>
</child-doc>
</relation>
</continuation>
<us-provisional-application>
<document-id>
<country>US</country>
<doc-number>62339148</doc-number>
<date>20160520</date>
</document-id>
</us-provisional-application>
</us-related-documents>
<us-parties>
<us-applicants>
<us-applicant sequence="00" app-type="applicant" designation="us-only" applicant-authority-category="assignee">
<addressbook>
<orgname>Shady Spot, Inc.</orgname>
<address>
<city>Piedmont</city>
<state>SC</state>
<country>US</country>
</address>
</addressbook>
<residence>
<country>US</country>
</residence>
</us-applicant>
</us-applicants>
<inventors>
<inventor sequence="00" designation="us-only">
<addressbook>
<last-name>Gurley</last-name>
<first-name>Winifred</first-name>
<address>
<city>Piedmont</city>
<state>SC</state>
<country>US</country>
</address>
</addressbook>
</inventor>
<inventor sequence="01" designation="us-only">
<addressbook>
<last-name>Gurley</last-name>
<first-name>Paul</first-name>
<address>
<city>Piedmont</city>
<state>SC</state>
<country>US</country>
</address>
</addressbook>
</inventor>
</inventors>
</us-parties>
<assignees>
<assignee>
<addressbook>
<orgname>Shady Spot, Inc.</orgname>
<role>02</role>
<address>
<city>Piedmont</city>
<state>SC</state>
<country>US</country>
</address>
</addressbook>
</assignee>
</assignees>
</us-bibliographic-data-application>
<abstract id="abstract">
<p id="p-0001" num="0000">A self-contained, self-extending, roof-mounted shading apparatus, capable of both vertical and horizontal movement to provide shade for a vehicle.</p>
</abstract>
<drawings id="DRAWINGS">
<figure id="Fig-EMI-D00000" num="00000">
<img id="EMI-D00000" he="76.71mm" wi="158.75mm" file="US20200262283A1-20200820-D00000.TIF" alt="embedded image" img-content="drawing" img-format="tif"/>
</figure>
<figure id="Fig-EMI-D00001" num="00001">
<img id="EMI-D00001" he="222.00mm" wi="112.69mm" orientation="landscape" file="US20200262283A1-20200820-D00001.TIF" alt="embedded image" img-content="drawing" img-format="tif"/>
</figure>
<figure id="Fig-EMI-D00002" num="00002">
<img id="EMI-D00002" he="94.23mm" wi="182.71mm" file="US20200262283A1-20200820-D00002.TIF" alt="embedded image" img-content="drawing" img-format="tif"/>
</figure>
<figure id="Fig-EMI-D00003" num="00003">
<img id="EMI-D00003" he="214.29mm" wi="113.45mm" orientation="landscape" file="US20200262283A1-20200820-D00003.TIF" alt="embedded image" img-content="drawing" img-format="tif"/>
</figure>
<figure id="Fig-EMI-D00004" num="00004">
<img id="EMI-D00004" he="121.58mm" wi="188.98mm" file="US20200262283A1-20200820-D00004.TIF" alt="embedded image" img-content="drawing" img-format="tif"/>
</figure>
<figure id="Fig-EMI-D00005" num="00005">
<img id="EMI-D00005" he="242.65mm" wi="100.58mm" orientation="landscape" file="US20200262283A1-20200820-D00005.TIF" alt="embedded image" img-content="drawing" img-format="tif"/>
</figure>
<figure id="Fig-EMI-D00006" num="00006">
<img id="EMI-D00006" he="72.98mm" wi="183.56mm" file="US20200262283A1-20200820-D00006.TIF" alt="embedded image" img-content="drawing" img-format="tif"/>
</figure>
<figure id="Fig-EMI-D00007" num="00007">
<img id="EMI-D00007" he="110.83mm" wi="191.26mm" file="US20200262283A1-20200820-D00007.TIF" alt="embedded image" img-content="drawing" img-format="tif"/>
</figure>
<figure id="Fig-EMI-D00008" num="00008">
<img id="EMI-D00008" he="236.14mm" wi="127.00mm" orientation="landscape" file="US20200262283A1-20200820-D00008.TIF" alt="embedded image" img-content="drawing" img-format="tif"/>
</figure>
<figure id="Fig-EMI-D00009" num="00009">
<img id="EMI-D00009" he="218.86mm" wi="137.33mm" orientation="landscape" file="US20200262283A1-20200820-D00009.TIF" alt="embedded image" img-content="drawing" img-format="tif"/>
</figure>
<figure id="Fig-EMI-D00010" num="00010">
<img id="EMI-D00010" he="217.00mm" wi="147.40mm" orientation="landscape" file="US20200262283A1-20200820-D00010.TIF" alt="embedded image" img-content="drawing" img-format="tif"/>
</figure>
<figure id="Fig-EMI-D00011" num="00011">
<img id="EMI-D00011" he="236.05mm" wi="128.44mm" orientation="landscape" file="US20200262283A1-20200820-D00011.TIF" alt="embedded image" img-content="drawing" img-format="tif"/>
</figure>
<figure id="Fig-EMI-D00012" num="00012">
<img id="EMI-D00012" he="130.73mm" wi="193.46mm" file="US20200262283A1-20200820-D00012.TIF" alt="embedded image" img-content="drawing" img-format="tif"/>
</figure>
<figure id="Fig-EMI-D00013" num="00013">
<img id="EMI-D00013" he="113.37mm" wi="144.95mm" file="US20200262283A1-20200820-D00013.TIF" alt="embedded image" img-content="drawing" img-format="tif"/>
</figure>
<figure id="Fig-EMI-D00014" num="00014">
<img id="EMI-D00014" he="235.03mm" wi="151.05mm" orientation="landscape" file="US20200262283A1-20200820-D00014.TIF" alt="embedded image" img-content="drawing" img-format="tif"/>
</figure>
<figure id="Fig-EMI-D00015" num="00015">
<img id="EMI-D00015" he="88.22mm" wi="168.32mm" file="US20200262283A1-20200820-D00015.TIF" alt="embedded image" img-content="drawing" img-format="tif"/>
</figure>
<figure id="Fig-EMI-D00016" num="00016">
<img id="EMI-D00016" he="108.80mm" wi="182.63mm" file="US20200262283A1-20200820-D00016.TIF" alt="embedded image" img-content="drawing" img-format="tif"/>
</figure>
<figure id="Fig-EMI-D00017" num="00017">
<img id="EMI-D00017" he="102.36mm" wi="173.48mm" file="US20200262283A1-20200820-D00017.TIF" alt="embedded image" img-content="drawing" img-format="tif"/>
</figure>
<figure id="Fig-EMI-D00018" num="00018">
<img id="EMI-D00018" he="233.17mm" wi="51.31mm" orientation="landscape" file="US20200262283A1-20200820-D00018.TIF" alt="embedded image" img-content="drawing" img-format="tif"/>
</figure>
<figure id="Fig-EMI-D00019" num="00019">
<img id="EMI-D00019" he="222.59mm" wi="104.31mm" orientation="landscape" file="US20200262283A1-20200820-D00019.TIF" alt="embedded image" img-content="drawing" img-format="tif"/>
</figure>
<figure id="Fig-EMI-D00020" num="00020">
<img id="EMI-D00020" he="238.17mm" wi="109.05mm" orientation="landscape" file="US20200262283A1-20200820-D00020.TIF" alt="embedded image" img-content="drawing" img-format="tif"/>
</figure>
<figure id="Fig-EMI-D00021" num="00021">
<img id="EMI-D00021" he="107.53mm" wi="161.04mm" file="US20200262283A1-20200820-D00021.TIF" alt="embedded image" img-content="drawing" img-format="tif"/>
</figure>
</drawings>
<description id="description">
<?summary-of-invention description="Summary of Invention" end="lead"?>
<heading id="h-0001" level="1">BACKGROUND OF THE INVENTION</heading>
<heading id="h-0002" level="1">1) Field of the Invention</heading>
<p id="p-0002" num="0001">The present invention relates to a vehicle roof-mounted shading apparatus, capable of both vertical and horizontal movement, to shade a vehicle from the sun.</p>
<heading id="h-0003" level="1">2) Description of Related Art</heading>
<p id="p-0003" num="0002">The interior of a car parked outdoors on a hot sunny day can reach very high temperatures in a short period of time. This drastic temperature increase is caused by a combination of hot temperatures outside the car and lack of proper ventilation for the hot air to escape from within and surrounding the exterior of the car. Ultraviolet radiation from the sun also enters through the windshields and windows and heats the air in the car. The front windshield may also act like a magnifying glass, intensifying sun rays.</p>
<p id="p-0004" num="0003">These extreme conditions not only cause discomfort to the driver and passengers upon re-entering, but may also damage the interior of the car. Two methods that are normally used to reduce temperature build-up in a vehicle are tinting the windows or using sunshades. Tinting the window involves permanently installing a film on the window of the car. In some countries, this is not permitted by law.</p>
<p id="p-0005" num="0004">There have been a number of efforts to cover parked cars and protect them from very high internal temperatures caused by the sun's rays. To date, these efforts all have had designs that make them best suited for long term parking because of the difficulties one would have in using the various systems. Most sit on the car surface, which is not good for the vehicle's finish and traps heat at the vehicle exterior.</p>
<p id="p-0006" num="0005">Several efforts have tried to address all problems that could occur, such as rain, snow, hail, sleet, and wind as well as sun rays. Some devices have to be removed and stored in the trunk to operate the car. Other applications have to be wired into the car's electrical system or have parts welded onto the car roof or trunk or would need several people to deploy the device for use. For instance, Patel, U.S. Pat. No. 8,308,217, provides a sun shade for interior use of a vehicle. The shade includes a scissors type extension mechanism but lacks internally supported tubing and is incapable of both vertical and horizontal movement with respect to a vehicle.</p>
<p id="p-0082" num="0081">While the present subject matter has been described in detail with respect to specific exemplary embodiments and methods thereof, it will be appreciated that those skilled in the art, upon attaining an understanding of the foregoing may readily produce alterations to, variations of, and equivalents to such embodiments. Accordingly, the scope of the present disclosure is by way of example rather than by way of limitation, and the subject disclosure does not preclude inclusion of such modifications, variations and/or additions to the present subject matter as would be readily apparent to one of ordinary skill in the art using the teachings disclosed herein.</p>
<?detailed-description description="Detailed Description" end="tail"?>
</description>
<us-claim-statement>What is claimed is:</us-claim-statement>
<claims id="claims">
<claim id="CLM-01-19" num="01-19">
<claim-text><b>1</b>.-<b>19</b>. (canceled)</claim-text>
</claim>
<claim id="CLM-00020" num="00020">
<claim-text><b>20</b>. A system for providing shade comprising:
<claim-text>a device shell;</claim-text>
<claim-text>a vertical extension unit;</claim-text>
<claim-text>a horizontal extension unit;</claim-text>
<claim-text>a sunshade material;</claim-text>
<claim-text>at least one collapsible tube formed from nested segments; and</claim-text>
<claim-text>an extendable support positioned within the nested segments of the at least one collapsible tube.</claim-text>
</claim-text>
</claim>
<claim id="CLM-00021" num="00021">
<claim-text><b>21</b>. The system of <claim-ref idref="CLM-00020">claim 20</claim-ref>, wherein the system includes at least one motor for vertical and horizontal movement.</claim-text>
</claim>
<claim id="CLM-00022" num="00022">
<claim-text><b>22</b>. The system of <claim-ref idref="CLM-00020">claim 20</claim-ref>, wherein the extendable support is affixed to a distal segment of the at least one collapsible tube.</claim-text>
</claim>
<claim id="CLM-00023" num="00023">
<claim-text><b>23</b>. The system of <claim-ref idref="CLM-00020">claim 20</claim-ref>, wherein the extendable support is a coiled strip.</claim-text>
</claim>
<claim id="CLM-00024" num="00024">
<claim-text><b>24</b>. The system of <claim-ref idref="CLM-00020">claim 20</claim-ref>, wherein the device shell is hinged and includes a lid.</claim-text>
</claim>
<claim id="CLM-00025" num="00025">
<claim-text><b>25</b>. The system of <claim-ref idref="CLM-00024">claim 24</claim-ref>, wherein the lid opens when the system raises vertically and closes when the system lowers vertically.</claim-text>
</claim>
<claim id="CLM-00026" num="00026">
<claim-text><b>26</b>. The system of <claim-ref idref="CLM-00020">claim 20</claim-ref>, wherein vertical extension is achieved via at least one scissor bracket.</claim-text>
</claim>
<claim id="CLM-00027" num="00027">
<claim-text><b>27</b>. The system of <claim-ref idref="CLM-00020">claim 20</claim-ref>, wherein the system includes at least two vertical extension units.</claim-text>
</claim>
<claim id="CLM-00028" num="00028">
<claim-text><b>28</b>. The system of <claim-ref idref="CLM-00024">claim 24</claim-ref>, wherein a surface of the lid is contoured.</claim-text>
</claim>
<claim id="CLM-00029" num="00029">
<claim-text><b>29</b>. The system of <claim-ref idref="CLM-00024">claim 24</claim-ref>, wherein the system may be solar powered, battery powered, or alternating current powered.</claim-text>
</claim>
<claim id="CLM-00030" num="00030">
<claim-text><b>30</b>. The system of <claim-ref idref="CLM-00024">claim 24</claim-ref>, wherein the system comprises a woven or nonwoven material which contains ultraviolet ray protection.</claim-text>
</claim>
<claim id="CLM-00031" num="00031">
<claim-text><b>31</b>. The system of <claim-ref idref="CLM-00024">claim 24</claim-ref>, wherein upon retraction of the sunshade material, the sunshade material is gathered by a cuff</claim-text>
</claim>
<claim id="CLM-00032" num="00032">
<claim-text><b>32</b>. A method for deploying a canopy comprising:
<claim-text>storing a canopy within a device shell;</claim-text>
<claim-text>forming at least one collapsible tube comprising nested segments;</claim-text>
<claim-text>substantially vertically raising a vertical extension unit from the device shell; and</claim-text>
<claim-text>substantially horizontally extending, with respect to the device shell, an extendable support positioned within the nested segments of the at least one collapsible tube to extend and unfold the canopy.</claim-text>
</claim-text>
</claim>
<claim id="CLM-00033" num="00033">
<claim-text><b>33</b>. The method of <claim-ref idref="CLM-00032">claim 32</claim-ref>, further comprising including at least one motor for vertical and horizontal movement.</claim-text>
</claim>
<claim id="CLM-00034" num="00034">
<claim-text><b>34</b>. The system of <claim-ref idref="CLM-00032">claim 32</claim-ref>, further comprising affixing the extendable support to a distal segment of the at least one collapsible tube.</claim-text>
</claim>
<claim id="CLM-00035" num="00035">
<claim-text><b>35</b>. The system of <claim-ref idref="CLM-00032">claim 32</claim-ref>, further comprising wherein the extendable support is a coiled strip.</claim-text>
</claim>
<claim id="CLM-00036" num="00036">
<claim-text><b>36</b>. The system of <claim-ref idref="CLM-00032">claim 32</claim-ref>, further comprising forming the device shell to be hinged and to include a lid.</claim-text>
</claim>
<claim id="CLM-00037" num="00037">
<claim-text><b>37</b>. The system of <claim-ref idref="CLM-00036">claim 36</claim-ref>, further comprising opening the lid when the vertical extension unit rises substantially vertically and closing the lid when the vertical extension unit lowers substantially vertically.</claim-text>
</claim>
<claim id="CLM-00038" num="00038">
<claim-text><b>38</b>. The system of <claim-ref idref="CLM-00032">claim 32</claim-ref>, further comprising achieving vertical extension via at least one scissor bracket.</claim-text>
</claim>
<claim id="CLM-00039" num="00039">
<claim-text><b>39</b>. The system of <claim-ref idref="CLM-00032">claim 32</claim-ref>, further comprising at least two vertical extension units.</claim-text>
</claim>
<claim id="CLM-00040" num="00040">
<claim-text><b>40</b>. The system of <claim-ref idref="CLM-00032">claim 32</claim-ref>, further comprising contouring a surface of the lid.</claim-text>
</claim>
</claims>
</us-patent-application>

And here is my code following the first answer to the above mentioned question.

import pandas as pd
import xml.etree.ElementTree as ET


def iter_docs(author):
    author_attr = author.attrib
    #print(author.attrib)
    for doc in author.iter():
        
        doc_dict = author_attr.copy()
        doc_dict.update(doc.attrib)
        doc_dict['data'] = doc.text
        print(doc_dict)
        yield doc_dict

etree = ET.parse("1.xml") #create an ElementTree object 
doc_df = pd.DataFrame(list(iter_docs(etree.getroot())))

print(doc_df.head())

However most of the columns of the data frame are NaN, not to mention that there should be only one row. I think this is because this file has a more complicated format than the one in the referred question. How should I modify the Python code?

Reza
  • 388
  • 2
  • 14

1 Answers1

0

I have a partial solution you can further look into. First of all, I don't think the resulting dataframe will have just one row.

You can use pandas-read-xml package

pip install pandas-read-xml
import pandas_read_xml as pdx
from pandas_read_xml import fully_flatten

df = pdx.read_xml('1.xml').T

Will read in the XML file.

If you want to "flatten the data"

df = pdx.read_xml('1.xml').T.pipe(fully_flatten)

will create additional columns and rows as it flattens the data.

Note: If you are working with multiple XML files, say in a ZIP file, you can read all of the XML files at once.

df = pdx.read_xml('patents.zip').T
min
  • 231
  • 2
  • 6