Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip XML element text #182

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions sdmx/reader/xml/v21.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def info_from_element(cls, elem):
for k in ("class", "package"):
result[k] = elem.attrib.get(k, None)
elif elem.tag == "URN":
result = sdmx.urn.match(elem.text)
result = sdmx.urn.match(elem.text.strip())
# If the URN doesn't specify an item ID, it is probably a reference to a
# MaintainableArtefact, so target_id and id are the same
result.update(target_id=result["item_id"] or result["id"])
Expand Down Expand Up @@ -355,7 +355,7 @@ def _st(reader, elem):

@end("mes:Extracted mes:Prepared mes:ReportingBegin mes:ReportingEnd")
def _datetime(reader, elem):
text, n = re.subn(r"(.*\.)(\d{6})\d+(\+.*)", r"\1\2\3", elem.text)
text, n = re.subn(r"(.*\.)(\d{6})\d+(\+.*)", r"\1\2\3", elem.text.strip())
if n > 0:
log.debug(f"Truncate sub-microsecond time in <{QName(elem).localname}>")

Expand All @@ -371,7 +371,10 @@ def _datetime(reader, elem):
def _localization(reader, elem):
reader.push(
elem,
(elem.attrib.get(reader.qname("xml:lang"), model.DEFAULT_LOCALE), elem.text),
(
elem.attrib.get(reader.qname("xml:lang"), model.DEFAULT_LOCALE),
elem.text.strip(),
),
)


Expand Down Expand Up @@ -753,7 +756,7 @@ def _key0(reader, elem):
"ToVtlSubSpace": model.ToVTLSpaceKey,
}[parent]

return cls(key=elem.text)
return cls(key=elem.text.strip())


@end("str:DataKeySet")
Expand All @@ -769,7 +772,7 @@ def _p(reader, elem):
reader.push(
elem,
model.Period(
is_inclusive=elem.attrib["isInclusive"], period=isoparse(elem.text)
is_inclusive=elem.attrib["isInclusive"], period=isoparse(elem.text.strip())
),
)

Expand Down
8 changes: 4 additions & 4 deletions sdmx/reader/xml/v30.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Reference(BaseReference):
@classmethod
def info_from_element(cls, elem):
try:
result = sdmx.urn.match(elem.text)
result = sdmx.urn.match(elem.text.strip())
# If the URN doesn't specify an item ID, it is probably a reference to a
# MaintainableArtefact, so target_id and id are the same
result.update(target_id=result["item_id"] or result["id"])
Expand Down Expand Up @@ -84,13 +84,13 @@ class Reader(XMLEventReader):
@end("str:Codelist")
def _cl(reader, elem):
try:
sdmx.urn.match(elem.text)
sdmx.urn.match(elem.text.strip())
except ValueError:
result = v21._itemscheme(reader, elem)
result.extends = reader.pop_all(model.CodelistExtension)
return result
else:
reader.push(elem, elem.text)
reader.push(elem, elem.text.strip())


@end("str:CodelistExtension")
Expand All @@ -111,7 +111,7 @@ def _code_selection(reader, elem):

@end("str:MemberValue")
def _mv(reader, elem):
return reader.model.MemberValue(value=elem.text)
return reader.model.MemberValue(value=elem.text.strip())


@end("str:GeoGridCodelist")
Expand Down
Loading