jason m jason m - 1 month ago 11
Python Question

lxml or other library parsing nested xml with xpath

I have XML of the following structure:

<SEC-DOCUMENT>0001209191-16-145281.txt : 20161006
<SEC-HEADER>0001209191-16-145281.hdr.sgml : 20161006
<ACCEPTANCE-DATETIME>20161006175047
ACCESSION NUMBER: 0001209191-16-145281
CONFORMED SUBMISSION TYPE: 4
PUBLIC DOCUMENT COUNT: 1
CONFORMED PERIOD OF REPORT: 20161006
FILED AS OF DATE: 20161006
DATE AS OF CHANGE: 20161006

ISSUER:

COMPANY DATA:
COMPANY CONFORMED NAME: TEJON RANCH CO
CENTRAL INDEX KEY: 0000096869
STANDARD INDUSTRIAL CLASSIFICATION: REAL ESTATE [6500]
IRS NUMBER: 770196136
STATE OF INCORPORATION: DE
FISCAL YEAR END: 1231

BUSINESS ADDRESS:
STREET 1: 4436 LEBEC ROAD
STREET 2: PO BOX 1000
CITY: LEBEC
STATE: CA
ZIP: 93243
BUSINESS PHONE: 6612483000

MAIL ADDRESS:
STREET 1: 4436 LEBEC RD
STREET 2: PO BOX 1000
CITY: LEBEC
STATE: CA
ZIP: 93243

REPORTING-OWNER:

OWNER DATA:
COMPANY CONFORMED NAME: Bielli Gregory S.
CENTRAL INDEX KEY: 0001597159

FILING VALUES:
FORM TYPE: 4
SEC ACT: 1934 Act
SEC FILE NUMBER: 001-07183
FILM NUMBER: 161925684

MAIL ADDRESS:
STREET 1: P.O. BOX 1000
CITY: LEBEC
STATE: CA
ZIP: 93243
</SEC-HEADER>
<DOCUMENT>
<TYPE>4
<SEQUENCE>1
<FILENAME>doc4.xml
<DESCRIPTION>FORM 4 SUBMISSION
<TEXT>
<XML>
<?xml version="1.0"?>
<ownershipDocument>

<schemaVersion>X0306</schemaVersion>

<documentType>4</documentType>

<periodOfReport>2016-10-06</periodOfReport>

<notSubjectToSection16>0</notSubjectToSection16>

<issuer>
<issuerCik>0000096869</issuerCik>
<issuerName>TEJON RANCH CO</issuerName>
<issuerTradingSymbol>TRC</issuerTradingSymbol>
</issuer>

<reportingOwner>
<reportingOwnerId>
<rptOwnerCik>0001597159</rptOwnerCik>
<rptOwnerName>Bielli Gregory S.</rptOwnerName>
</reportingOwnerId>
<reportingOwnerAddress>
<rptOwnerStreet1>P.O. BOX 1000</rptOwnerStreet1>
<rptOwnerStreet2></rptOwnerStreet2>
<rptOwnerCity>TEJON RANCH</rptOwnerCity>
<rptOwnerState>CA</rptOwnerState>
<rptOwnerZipCode>93243</rptOwnerZipCode>
<rptOwnerStateDescription></rptOwnerStateDescription>
</reportingOwnerAddress>
<reportingOwnerRelationship>
<isDirector>1</isDirector>
<isOfficer>1</isOfficer>
<isTenPercentOwner>0</isTenPercentOwner>
<isOther>0</isOther>
<officerTitle>President/ CEO</officerTitle>
</reportingOwnerRelationship>
</reportingOwner>

<nonDerivativeTable>
<nonDerivativeTransaction>
<securityTitle>
<value>Tejon Ranch Co. Common Stock</value>
</securityTitle>
<transactionDate>
<value>2016-10-06</value>
</transactionDate>
<deemedExecutionDate></deemedExecutionDate>
<transactionCoding>
<transactionFormType>4</transactionFormType>
<transactionCode>A</transactionCode>
<equitySwapInvolved>0</equitySwapInvolved>
</transactionCoding>
<transactionTimeliness>
<value></value>
</transactionTimeliness>
<transactionAmounts>
<transactionShares>
<value>28122</value>
<footnoteId id="F1"/>
</transactionShares>
<transactionPricePerShare>
<value>24.32</value>
</transactionPricePerShare>
<transactionAcquiredDisposedCode>
<value>A</value>
</transactionAcquiredDisposedCode>
</transactionAmounts>
<postTransactionAmounts>
<sharesOwnedFollowingTransaction>
<value>55806</value>
<footnoteId id="F1"/>
</sharesOwnedFollowingTransaction>
</postTransactionAmounts>
<ownershipNature>
<directOrIndirectOwnership>
<value>D</value>
</directOrIndirectOwnership>
</ownershipNature>
</nonDerivativeTransaction>
<nonDerivativeTransaction>
<securityTitle>
<value>Tejon Ranch Co. Common Stock</value>
</securityTitle>
<transactionDate>
<value>2016-10-06</value>
</transactionDate>
<deemedExecutionDate></deemedExecutionDate>
<transactionCoding>
<transactionFormType>4</transactionFormType>
<transactionCode>F</transactionCode>
<equitySwapInvolved>0</equitySwapInvolved>
</transactionCoding>
<transactionTimeliness>
<value></value>
</transactionTimeliness>
<transactionAmounts>
<transactionShares>
<value>12753</value>
<footnoteId id="F1"/>
<footnoteId id="F2"/>
</transactionShares>
<transactionPricePerShare>
<value>24.32</value>
</transactionPricePerShare>
<transactionAcquiredDisposedCode>
<value>D</value>
</transactionAcquiredDisposedCode>
</transactionAmounts>
<postTransactionAmounts>
<sharesOwnedFollowingTransaction>
<value>43053</value>
<footnoteId id="F1"/>
</sharesOwnedFollowingTransaction>
</postTransactionAmounts>
<ownershipNature>
<directOrIndirectOwnership>
<value>D</value>
</directOrIndirectOwnership>
</ownershipNature>
</nonDerivativeTransaction>
</nonDerivativeTable>

<footnotes>
<footnote id="F1">Shares are held in the Bielli Family Trust</footnote>
<footnote id="F2">Shares used for taxes</footnote>
</footnotes>

<remarks></remarks>

<ownerSignature>
<signatureName>/s/ Gregory S. Bielli</signatureName>
<signatureDate>2016-10-06</signatureDate>
</ownerSignature>
</ownershipDocument>
</XML>
</TEXT>
</DOCUMENT>
</SEC-DOCUMENT>


If I wanted to extract something like
nonDerivativeTransaction


I would normally think to do something like
xpath('//nonDerivativeTransaction')
, but I cannot figure out the proper query string.

Like if I were using selenium and wrote:

driver.find_elements_by_xpath('//nonDerivativeTransaction')


I have tried things like:

import urllib2
from lxml import etree
from lxml import html
response = urllib2.urlopen('ftp://ftp.sec.gov/edgar/data/96869/0001209191-16-145281.txt')
html_doc = response.read()
root = html.fromstring(html_doc)
tree = root.getroottree()
x=tree.xpath("nonderivativetable")


but with no luck.

How would I solve this problem?

Answer

Unlike lxml.etree, lxml.html converts all element names to lower-case. You can see this by printing the root element -something like html.tostring(root)- either to console or to a file. That said, so the correct XPath to get nonDerivativeTransaction elements would be :

tree.xpath("//nonderivativetransaction")

Using the above XPath after code blocks posted at the end of the question returned 2 elements when I tested.