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)

Skills: Python, XML

See more: 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

About the Employer:
( 4 reviews ) Wellington, New Zealand

Project ID: #17173124

19 freelancers are bidding on average $114 for this job

$155 NZD in 3 days
(14 Reviews)
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 More

$155 NZD in 3 days
(74 Reviews)
5.9
$155 NZD in 3 days
(23 Reviews)
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 More

$155 NZD in 3 days
(7 Reviews)
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 More

$122 NZD in 2 days
(17 Reviews)
4.0
gregorybliault

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

$46 NZD in 3 days
(10 Reviews)
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.

$111 NZD in 3 days
(3 Reviews)
3.6
$100 NZD in 1 day
(4 Reviews)
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 More

$100 NZD in 3 days
(5 Reviews)
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 More

$222 NZD in 3 days
(2 Reviews)
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. :)

$100 NZD in 3 days
(6 Reviews)
2.5
lightingdavid

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

$155 NZD in 3 days
(2 Reviews)
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 More

$100 NZD in 3 days
(1 Review)
2.0
$155 NZD in 2 days
(2 Reviews)
1.4
$111 NZD in 2 days
(1 Review)
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())

$36 NZD in 3 days
(0 Reviews)
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 More

$30 NZD in 1 day
(1 Review)
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 More

$88 NZD in 3 days
(0 Reviews)
0.0
$66 NZD in 1 day
(0 Reviews)
0.0