Class XmlRecordReader


public class XmlRecordReader extends DataReader
Obtains records from an XML stream, turning each element matched by a record break into a record of its child elements (as nested records) and attributes (as @name fields).
  • Constructor Details

    • XmlRecordReader

      public XmlRecordReader(XMLStreamReader reader)
      Creates a reader for an existing StAX stream; closing this reader closes the stream reader but not its underlying input.
    • XmlRecordReader

      public XmlRecordReader(File file)
    • XmlRecordReader

      public XmlRecordReader(Reader reader)
  • Method Details

    • isDebug

      public boolean isDebug()
      Indicates if each node read is logged at debug level (default is false).
    • setDebug

      public XmlRecordReader setDebug(boolean debug)
      Indicates if each node read is logged at debug level (default is false).
    • isAddTextToParent

      public boolean isAddTextToParent()
      Return true if each child node's text should be concatenated to its parent during parsing (defaults to false).
    • setAddTextToParent

      public XmlRecordReader setAddTextToParent(boolean addTextToParent)
      Indicates if each child node's text should be concatenated to its parent during parsing (defaults to false). Setting this to true will result in higher memory consumption.
    • isIgnoreNamespaces

      public boolean isIgnoreNamespaces()
      Indicates if namespaces on elements and attributes are to be removed (default to true).
    • setIgnoreNamespaces

      public XmlRecordReader setIgnoreNamespaces(boolean ignoreNamespaces)
      Indicates if namespaces on elements and attributes are to be removed (default to true).
    • addRecordBreak

      public XmlRecordReader addRecordBreak(String locationPathAsString)
      Adds a location path (for example //book) whose matching elements are each read as one record.
    • isRecordBreak

      protected boolean isRecordBreak(XmlNode node)
      Returns true if the node matches any location path added with addRecordBreak(String).
    • close

      public void close()
      Description copied from class: DataEndpoint
      Indicates that this endpoint has finished reading or writing.
      Overrides:
      close in class DataEndpoint
    • isIgnoreEmptyText

      public boolean isIgnoreEmptyText()
    • setIgnoreEmptyText

      public XmlRecordReader setIgnoreEmptyText(boolean ignoreEmptyText)
    • isMapTextRecordsToFields

      public boolean isMapTextRecordsToFields()
      Indicates if elements holding only text (or nothing) become plain field values (or null) instead of nested records (default is true).
    • setMapTextRecordsToFields

      public XmlRecordReader setMapTextRecordsToFields(boolean mapTextRecordsToFields)
      Indicates if elements holding only text (or nothing) become plain field values (or null) instead of nested records (default is true).
    • readImpl

      protected Record readImpl() throws Throwable
      Description copied from class: DataReader
      Overridden by subclasses to read the next record from this DataReader. The default implementation of DataReader.read() now insures that this method will not be called again after it returns a null.

      If no record is available, null will be returned.

      Contract for subclasses (see also docs/authoring/DataReader.md):

      Specified by:
      readImpl in class DataReader
      Throws:
      Throwable
    • updateCurrentNode

      protected void updateCurrentNode() throws DataException
      Reads the next XML event and updates the current node: a start element opens a child node, an end element returns to the parent and text is added to the current node.
      Throws:
      DataException
    • isLineageSupported

      public boolean isLineageSupported()
      Description copied from class: DataReader
      Indicates if this reader can capture record and field lineage (false unless overridden by a reader that supports it).
      Overrides:
      isLineageSupported in class DataReader
    • addLineage

      protected Record addLineage(Record record)
      Description copied from class: DataReader
      Called by DataReader.read() for each record from DataReader.readImpl() while lineage is saved; the default copies recordLineage into every field along with its original index and name. Overrides set their source details on recordLineage first and end with super.addLineage(record).
      Overrides:
      addLineage in class DataReader
    • addExceptionProperties

      public DataException addExceptionProperties(DataException exception)
      Description copied from class: Endpoint
      Adds this endpoint's current state to a DataException. Since this method is called whenever an exception is thrown, subclasses should override it to add their specific information.
      Overrides:
      addExceptionProperties in class DataReader
    • isAutoCloseReader

      public boolean isAutoCloseReader()
      Indicates if the Reader passed to the constructor is closed when this reader closes (default is true); a file opened by this reader is always closed.
    • setAutoCloseReader

      public XmlRecordReader setAutoCloseReader(boolean autoCloseReader)
      Indicates if the Reader passed to the constructor is closed when this reader closes (default is true); a file opened by this reader is always closed.