View Source Xml (idmlx v0.1.0)

A utility module for parsing and extracting data from XML files using SweetXml.

Summary

Functions

Exports a fragment of an XML file based on the given XPath.

Parses an XML file based on the given specification and optional subspecification.

Parses attributes from an XML file based on the given specification.

Functions

export_fragment(file_path, xpath)

Exports a fragment of an XML file based on the given XPath.

Parameters

  • file_path: The path to the XML file.
  • xpath: The XPath specification for selecting the fragment to export.

Returns

  • The selected XML fragment.
  • {:error, reason}: An error tuple with a reason for failure.

parse(file_path, spec, subspec \\ [])

Parses an XML file based on the given specification and optional subspecification.

Parameters

  • file_path: The path to the XML file.
  • spec: The main XPath specification for parsing.
  • subspec: An optional list of subspecifications for more detailed parsing.

Returns

  • {:ok, dom}: The parsed XML document object model.
  • {:error, reason}: An error tuple with a reason for failure.

parse_attributes(file_path, spec)

Parses attributes from an XML file based on the given specification.

Parameters

  • file_path: The path to the XML file.
  • spec: The XPath specification for selecting elements whose attributes are to be parsed.

Returns

  • A list of maps containing attribute key-value pairs for each selected element.
  • {:error, reason}: An error tuple with a reason for failure.

parse_xml(xml, spec)

parse_xml(xml, spec, subspec)