Closed

python lxml - use etree to parse XSD (xml schema) via https

The below code works with http but not https.

Unsure if its because the parser is serving the schema as HTML instead of XML.

Been trying to Google for a quick answer but so far no joy.

from lxml import etree

import urllib2

schema_src_file = [login to view URL]('-- url ---')

schema_doc = [login to view URL](schema_src_file)

schema = [login to view URL](schema_doc)

***Please message me if you think you have an answer.

Further details and discoveries.

OS, software, and versions
ubuntu = 16.4 LTS
python = 2.7
lxml = 4.2.1

Python Code
from lxml import etree
import urllib2

schema_src_file = urllib2.urlopen('url to xsd')
schema_doc = etree.parse(schema_src_file)
schema = etree.XMLSchema(schema_doc)

The above code works with http.
As soon as the url is changed to https the code breaks.
The interesting thing is, if all the supporing xsd files are downloaded locally, to the directory that the script runs from, the code runs A OK.

The other interesting thing is, when using Oxygen, with either http or https the schema loads fine. This might be because oXygen uses xerces rather than libxml2? Or maybe because Oxygen sets the header(s) as XML instead of trying to convert it to HTML?

The main XSD Schema has multiple imports (see below). The called xsd files in turn loads further xsd files.

Imports from main XSD:
<xs:import namespace="http://www.w3.org/1998/Math/MathML" schemaLocation="mathml2/mathml2.xsd">
<xs:annotation>
<xs:documentation xml:lang="en"> Request elements make use of MathML for Special Authority form criteria. Schema location is relative to this resource. </xs:documentation>
</xs:annotation>
</xs:import>

<xs:import namespace="http://www.w3.org/1999/xhtml" schemaLocation="xhtml1-strict.xsd">
<xs:annotation>
<xs:documentation xml:lang="en"> Schedule Notes are encoded in xhtml. Schema location is relative to this resource. </xs:documentation>
</xs:annotation>
</xs:import>

<xs:import namespace="http://www.w3.org/1999/xlink" schemaLocation="xlink.xsd">
<xs:annotation>
<xs:documentation xml:lang="en"> xlink:href attributes are used to reference parts of the schedule </xs:documentation>
</xs:annotation>
</xs:import>


*** Please message if you think you have an answer

A similar issue seems to happen with simplexml_load_file when using https

$foXML = @simplexml_load_file(url to main xsd)

Beceriler: Python, XML

Daha fazlasını gör: parsing xsd in python, lxml xml schema, lxml validate against xsd, lxml parse url, generate xml schema python, lxml xml schema validation, python verify xml against xsd, python xml schema tutorial, sqlite python xml schema, python parse soap xml, python parse wikipedia xml dump, python library parse wikipedia xml, use sax parse big xml, use net parse xml file, python parse big xml, xml schema shell script, simple xml schema table, outlook contacts xml schema, create table xml schema, generic xml schema definition xsd gui translator

İşveren Hakkında:
( 4 değerlendirme ) Wellington, New Zealand

Proje NO: #17173124

Bu iş için 19 freelancer ortalamada $114 teklif veriyor

in %bids___i_period_sub_35% gün içinde155%project_currencyDetails_sign_sub_37% %project_currencyDetails_code_sub_38%
(14 Değerlendirme)
6.8
pkbsdmp

I am a python developer having 6 + experience in IT industry. I am expert in: * Python, Web Development (Django, Flask) * Django REST Framework (DRF) * CSS, HTML5, Javascript, AJAX, JQuery, Bootstrap * R Daha Fazla

in %bids___i_period_sub_35% gün içinde155%project_currencyDetails_sign_sub_37% %project_currencyDetails_code_sub_38%
(74 Değerlendirme)
5.9
in %bids___i_period_sub_35% gün içinde155%project_currencyDetails_sign_sub_37% %project_currencyDetails_code_sub_38%
(23 Değerlendirme)
4.4
maximwang8661

hello. nice to meet you. I am a good scraping expert. I have a lot of experience in scraping(beautifulsoup4, scrapy, selenium). I want to discuss about your project with you. If you hire me, I will complete your p Daha Fazla

in %bids___i_period_sub_35% gün içinde155%project_currencyDetails_sign_sub_37% %project_currencyDetails_code_sub_38%
(7 Değerlendirme)
4.1
ChanakyaNaag

Hey there! Please have a look at my reviews and ping me so that we can discuss further on project. My skills & experience: -- 2.7 years of experience in building automation tools using python. -- Seasoned profe Daha Fazla

in %bids___i_period_sub_35% gün içinde122%project_currencyDetails_sign_sub_37% %project_currencyDetails_code_sub_38%
(17 Değerlendirme)
4.0
gregorybliault

Hi, I am a python developer and I have experience parsing data Please contact me to discuss your project

in %bids___i_period_sub_35% gün içinde46%project_currencyDetails_sign_sub_37% %project_currencyDetails_code_sub_38%
(10 Değerlendirme)
3.9
arjun366333

Ready to start the work to resolve the issue in your code with lxml in pyhthon we can discuss more over chat,thanks regards Arjun S.

in %bids___i_period_sub_35% gün içinde111%project_currencyDetails_sign_sub_37% %project_currencyDetails_code_sub_38%
(3 Değerlendirme)
3.6
1 gün içinde %bids___i_sum_sub_32%%project_currencyDetails_sign_sub_33% NZD
(4 Değerlendirme)
3.1
RajuPitta

Hey There, I have very strong expertise in Python and is having more than five years of experience in enterprise level software development and automation using Python. I am very passionate about engineering and del Daha Fazla

in %bids___i_period_sub_35% gün içinde100%project_currencyDetails_sign_sub_37% %project_currencyDetails_code_sub_38%
(5 Değerlendirme)
2.8
ZhenExpert

Hello, I am a python developer having 7 years of experience. I can assure that we are on the same page from the word go as I have worked on projects similar to yours in the past. And, therefore I can easily accomplish Daha Fazla

in %bids___i_period_sub_35% gün içinde222%project_currencyDetails_sign_sub_37% %project_currencyDetails_code_sub_38%
(2 Değerlendirme)
3.3
yodebublr

Can you give me a chance? Python developer here from India and I would like to give this a try :) You can pay me up once you see that your issue is fixed. :)

in %bids___i_period_sub_35% gün içinde100%project_currencyDetails_sign_sub_37% %project_currencyDetails_code_sub_38%
(6 Değerlendirme)
2.5
lightingdavid

Hello. I have good skills in Excel and Python. Contact me please. Thanks................................................................................................................................

in %bids___i_period_sub_35% gün içinde155%project_currencyDetails_sign_sub_37% %project_currencyDetails_code_sub_38%
(2 Değerlendirme)
2.0
jacobcarl222

hello, how are you ? I read your requirement carefully, then very interested in your project. I work newly on this site, but have rich experience in programming using python. I can use several packages such as Daha Fazla

in %bids___i_period_sub_35% gün içinde100%project_currencyDetails_sign_sub_37% %project_currencyDetails_code_sub_38%
(1 Yorum)
2.0
in %bids___i_period_sub_35% gün içinde155%project_currencyDetails_sign_sub_37% %project_currencyDetails_code_sub_38%
(2 Değerlendirme)
1.4
in %bids___i_period_sub_35% gün içinde111%project_currencyDetails_sign_sub_37% %project_currencyDetails_code_sub_38%
(1 Yorum)
0.8
VladimirPy

use this scheme of work with xml from [login to view URL] import cElementTree as ET xml = [login to view URL]([login to view URL]('[login to view URL]').read())

in %bids___i_period_sub_35% gün içinde36%project_currencyDetails_sign_sub_37% %project_currencyDetails_code_sub_38%
(0 Değerlendirme)
0.0
bbrazsilveira

Hello, With over 12 years of demonstrated experience, I am an individual developer but have an ability as a company, I can work with local developers near me as a team for completing your project as well. Please Daha Fazla

1 gün içinde %bids___i_sum_sub_32%%project_currencyDetails_sign_sub_33% NZD
(1 Yorum)
0.0
md46135

Hello, I guess you are trying to scrape some website. From my experience, Selenium running Chromedriver combined with lxml is the best option. Code would be something like this: from selenium import webdriver fr Daha Fazla

in %bids___i_period_sub_35% gün içinde88%project_currencyDetails_sign_sub_37% %project_currencyDetails_code_sub_38%
(0 Değerlendirme)
0.0
1 gün içinde %bids___i_sum_sub_32%%project_currencyDetails_sign_sub_33% NZD
(0 Değerlendirme)
0.0