Python - load XSD schema from https url into lxml
Budget: $30 – $250 NZD
I can solve the below by downloading all the resources first and then referencing them.
However I'd prefer an in memory solution if possible.
The below fails when I change the url from http to https:
#!/usr/bin/env python3.4.3
from lxml import etree
schema = 'https://schedule.pharmac.govt.nz/2006/07/Schedule.xsd'
schemadoc = etree.XMLSchema(file = schema)
I tried the below, of course it fails as its missing the other resources:
import urllib.request
import xmlschema
from lxml import etree
url = 'https://schedule.pharmac.govt.nz/2006/07/Schedule.xsd'
try:
with urllib.request.urlopen(url) as response:
webpage_content = response.read().decode('utf-8')
webpage_content = webpage_content.replace("\r", "")
webpage_content = webpage_content.encode('utf-8')
# print(webpage_content)
except urllib.error.URLError as e:
print(f"Error opening URL: {e}")
except Exception as e:
print(f"An unexpected error occurred: {e}")
xmlschema_doc = etree.fromstring(webpage_content)
xmlschema_doc = etree.XMLSchema(xmlschema_doc)
I'd like an in memory solution if possible
However I'd prefer an in memory solution if possible.
The below fails when I change the url from http to https:
#!/usr/bin/env python3.4.3
from lxml import etree
schema = 'https://schedule.pharmac.govt.nz/2006/07/Schedule.xsd'
schemadoc = etree.XMLSchema(file = schema)
I tried the below, of course it fails as its missing the other resources:
import urllib.request
import xmlschema
from lxml import etree
url = 'https://schedule.pharmac.govt.nz/2006/07/Schedule.xsd'
try:
with urllib.request.urlopen(url) as response:
webpage_content = response.read().decode('utf-8')
webpage_content = webpage_content.replace("\r", "")
webpage_content = webpage_content.encode('utf-8')
# print(webpage_content)
except urllib.error.URLError as e:
print(f"Error opening URL: {e}")
except Exception as e:
print(f"An unexpected error occurred: {e}")
xmlschema_doc = etree.fromstring(webpage_content)
xmlschema_doc = etree.XMLSchema(xmlschema_doc)
I'd like an in memory solution if possible