View Source Idmlx.Utils.Xml (idmlx v0.2.1)

A utility module for parsing, creating, and manipulating XML content. Provides functionality for both reading XML files and building XML elements.

Summary

Functions

Creates an XML element with the given name, attributes, and content.

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.

Converts an XML element to a string representation.

Functions

create_element(name, attributes, content \\ [])

Creates an XML element with the given name, attributes, and content.

Examples

iex> Idmlx.Utils.Xml.create_element("CharacterStyle", %{"Name" => "Heading"})
%{name: "CharacterStyle", attributes: %{"Name" => "Heading"}, content: []}

iex> Idmlx.Utils.Xml.create_element("Properties", %{}, ["Some content"])
%{name: "Properties", attributes: %{}, content: ["Some content"]}

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)

to_xml_string(element)

Converts an XML element to a string representation.