Problem
get_schema now reports each field's name, type, alias, string length and domain (#38). Many ArcGIS items also carry formal metadata (ISO 19139 / FGDC / ArcGIS format). Its entity-and-attribute section defines each field: a label, a definition, units and sometimes value ranges. Aliases rarely say that much. HUD's layers, for example, define no domains, so analysts still have to find out elsewhere what a field such as HCV_PUBLIC_PCT is a percentage of.
This was the optional last item in thealphacubicle#84 and was deferred from #38.
Proposal
- Fetch the item's metadata document (
{portal}/sharing/rest/content/items/{id}/info/metadata/metadata.xml on ArcGIS Online/Enterprise). Do it best-effort and cache it like layer descriptions, so a missing document or a 404 never fails the call.
- Parse it with the standard library
xml.etree.ElementTree, with no new dependency. Read the entity/attribute entries (eainfo/detailed/attr: attrlabl, attrdef, attrunit, and rdom/edom where present).
get_schema adds a Definition: line (and units) per field when the metadata has one, matched by field name. Treat the text as portal content: html_to_text, portal_block, and caps.
- Security: parse with entity expansion off.
ElementTree does not resolve external entities, but guard against oversized documents with a size cap before parsing, and consider defusedxml only if its size fits the Lambda budget.
- Tests: an FGDC-style fixture, a missing document, malformed XML, a size cap, and name matching that's case-insensitive.
References
Problem
get_schemanow reports each field's name, type, alias, string length and domain (#38). Many ArcGIS items also carry formal metadata (ISO 19139 / FGDC / ArcGIS format). Its entity-and-attribute section defines each field: a label, a definition, units and sometimes value ranges. Aliases rarely say that much. HUD's layers, for example, define no domains, so analysts still have to find out elsewhere what a field such asHCV_PUBLIC_PCTis a percentage of.This was the optional last item in thealphacubicle#84 and was deferred from #38.
Proposal
{portal}/sharing/rest/content/items/{id}/info/metadata/metadata.xmlon ArcGIS Online/Enterprise). Do it best-effort and cache it like layer descriptions, so a missing document or a 404 never fails the call.xml.etree.ElementTree, with no new dependency. Read the entity/attribute entries (eainfo/detailed/attr:attrlabl,attrdef,attrunit, andrdom/edomwhere present).get_schemaadds aDefinition:line (and units) per field when the metadata has one, matched by field name. Treat the text as portal content:html_to_text,portal_block, and caps.ElementTreedoes not resolve external entities, but guard against oversized documents with a size cap before parsing, and considerdefusedxmlonly if its size fits the Lambda budget.References