Reading files


In [33]:
from pykml import parser
import os

In [53]:
file = 'база-пирамид.kml'

home_dir = os.path.expanduser('~')
kml_file = os.path.join(home_dir, 'dev/piramidy/рабочие-файлы', \
                        file)

In [54]:
with open(kml_file) as f:
    doc = parser.parse(f)

In [55]:
kml_file


Out[55]:
'/Users/alex/dev/piramidy/рабочие-файлы/база-пирамид.kml'

Validation


In [12]:
from pykml.parser import Schema

In [13]:
schema_gx = Schema("kml22gx.xsd")

In [15]:
schema_gx.assertValid(doc)


---------------------------------------------------------------------------
DocumentInvalid                           Traceback (most recent call last)
<ipython-input-15-0dcc65f24f0b> in <module>()
----> 1 schema_gx.assertValid(doc)

/usr/local/lib/python3.6/site-packages/pykml/parser.py in assertValid(self, doc)
     38         when compared to the XML Schema.
     39         """
---> 40         return self.schema.assertValid(doc)
     41 
     42 def fromstring(text, schema=None):

src/lxml/lxml.etree.pyx in lxml.etree._Validator.assertValid (src/lxml/lxml.etree.c:186669)()

DocumentInvalid: Element '{http://www.opengis.net/kml/2.2}LineStyle': This element is not expected. Expected is ( {http://www.opengis.net/kml/2.2}ListStyle )., line 19

In [56]:
doc.getiterator()


Out[56]:
<lxml.etree.ElementDepthFirstIterator at 0x1125bfa68>

In [ ]: