Class XmlRecordReader
java.lang.Object
com.northconcepts.datapipeline.core.DataObject
com.northconcepts.datapipeline.core.Endpoint
com.northconcepts.datapipeline.core.DataEndpoint
com.northconcepts.datapipeline.core.DataReader
com.northconcepts.datapipeline.xml.XmlRecordReader
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).-
Field Summary
Fields inherited from class com.northconcepts.datapipeline.core.DataReader
fieldLineage, recordLineageFields inherited from class com.northconcepts.datapipeline.core.DataEndpoint
lastRecord, PRODUCT, PRODUCT_VERSION, VENDOR, XML_INPUT_FACTORY_KEYFields inherited from class com.northconcepts.datapipeline.core.Endpoint
BUFFER_SIZE, captureElapsedTime, DEFAULT_READ_BUFFER_SIZEFields inherited from class com.northconcepts.datapipeline.core.DataObject
id, log, name, TIMESTAMP_FORMAT -
Constructor Summary
ConstructorsConstructorDescriptionXmlRecordReader(File file) XmlRecordReader(Reader reader) XmlRecordReader(XMLStreamReader reader) Creates a reader for an existing StAX stream; closing this reader closes the stream reader but not its underlying input. -
Method Summary
Modifier and TypeMethodDescriptionaddExceptionProperties(DataException exception) Adds this endpoint's current state to aDataException.protected RecordaddLineage(Record record) Called byDataReader.read()for each record fromDataReader.readImpl()while lineage is saved; the default copiesrecordLineageinto every field along with its original index and name.addRecordBreak(String locationPathAsString) Adds a location path (for example//book) whose matching elements are each read as one record.voidclose()Indicates that this endpoint has finished reading or writing.booleanReturn true if each child node's text should be concatenated to its parent during parsing (defaults to false).booleanIndicates if theReaderpassed to the constructor is closed when this reader closes (default is true); a file opened by this reader is always closed.booleanisDebug()Indicates if each node read is logged at debug level (default is false).booleanbooleanIndicates if namespaces on elements and attributes are to be removed (default to true).booleanIndicates if this reader can capture record and field lineage (false unless overridden by a reader that supports it).booleanIndicates if elements holding only text (or nothing) become plain field values (or null) instead of nested records (default is true).protected booleanisRecordBreak(XmlNode node) Returns true if the node matches any location path added withaddRecordBreak(String).protected RecordreadImpl()Overridden by subclasses to read the next record from thisDataReader.setAddTextToParent(boolean addTextToParent) Indicates if each child node's text should be concatenated to its parent during parsing (defaults to false).setAutoCloseReader(boolean autoCloseReader) Indicates if theReaderpassed to the constructor is closed when this reader closes (default is true); a file opened by this reader is always closed.setDebug(boolean debug) Indicates if each node read is logged at debug level (default is false).setIgnoreEmptyText(boolean ignoreEmptyText) setIgnoreNamespaces(boolean ignoreNamespaces) Indicates if namespaces on elements and attributes are to be removed (default to true).setMapTextRecordsToFields(boolean mapTextRecordsToFields) Indicates if elements holding only text (or nothing) become plain field values (or null) instead of nested records (default is true).protected voidReads 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.Methods inherited from class com.northconcepts.datapipeline.core.DataReader
available, getBufferSize, getNestedEndpoint, getNestedReader, getReader, getRootEndpoint, getRootReader, isExhausted, isSaveLineage, peek, pop, push, read, setSaveLineage, skipMethods inherited from class com.northconcepts.datapipeline.core.DataEndpoint
decrementRecordCount, enableJmx, getLastRecord, getRecordCount, getRecordCountAsBigInteger, getRecordCountAsString, incrementRecordCount, isRecordCountBigInteger, open, resetRecordCount, toStringMethods inherited from class com.northconcepts.datapipeline.core.Endpoint
addElapsedtime, assertClosed, assertNotOpened, assertOpened, finalize, getClosedOn, getDescription, getElapsedTime, getElapsedTimeAsString, getOpenedOn, getOpenElapsedTime, getOpenElapsedTimeAsString, getSelfTime, getSelfTimeAsString, getState, isCaptureElapsedTime, isClosed, isOpen, setCaptureElapsedTime, setDescription
-
Constructor Details
-
XmlRecordReader
Creates a reader for an existing StAX stream; closing this reader closes the stream reader but not its underlying input. -
XmlRecordReader
-
XmlRecordReader
-
-
Method Details
-
isDebug
public boolean isDebug()Indicates if each node read is logged at debug level (default is false). -
setDebug
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
Indicates if each child node's text should be concatenated to its parent during parsing (defaults to false). Setting this totruewill result in higher memory consumption. -
isIgnoreNamespaces
public boolean isIgnoreNamespaces()Indicates if namespaces on elements and attributes are to be removed (default to true). -
setIgnoreNamespaces
Indicates if namespaces on elements and attributes are to be removed (default to true). -
addRecordBreak
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 withaddRecordBreak(String). -
close
public void close()Description copied from class:DataEndpointIndicates that this endpoint has finished reading or writing.- Overrides:
closein classDataEndpoint
-
isIgnoreEmptyText
public boolean isIgnoreEmptyText() -
setIgnoreEmptyText
-
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
Indicates if elements holding only text (or nothing) become plain field values (or null) instead of nested records (default is true). -
readImpl
Description copied from class:DataReaderOverridden by subclasses to read the next record from thisDataReader. The default implementation ofDataReader.read()now insures that this method will not be called again after it returns anull.If no record is available,
nullwill be returned.Contract for subclasses (see also
docs/authoring/DataReader.md):- Return
nullexactly once to signal end-of-stream. - Do not call this method directly —
DataReader.read()is the template method that wraps exceptions, increments the record count, and tracks lineage. - Do not call
DataEndpoint.incrementRecordCount()here;DataReader.read()already does. - Throw raw exceptions;
DataReader.read()wraps them viaexception(throwable).
- Specified by:
readImplin classDataReader- Throws:
Throwable
- Return
-
updateCurrentNode
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:DataReaderIndicates if this reader can capture record and field lineage (false unless overridden by a reader that supports it).- Overrides:
isLineageSupportedin classDataReader
-
addLineage
Description copied from class:DataReaderCalled byDataReader.read()for each record fromDataReader.readImpl()while lineage is saved; the default copiesrecordLineageinto every field along with its original index and name. Overrides set their source details onrecordLineagefirst and end withsuper.addLineage(record).- Overrides:
addLineagein classDataReader
-
addExceptionProperties
Description copied from class:EndpointAdds this endpoint's current state to aDataException. Since this method is called whenever an exception is thrown, subclasses should override it to add their specific information.- Overrides:
addExceptionPropertiesin classDataReader
-
isAutoCloseReader
public boolean isAutoCloseReader()Indicates if theReaderpassed to the constructor is closed when this reader closes (default is true); a file opened by this reader is always closed. -
setAutoCloseReader
Indicates if theReaderpassed to the constructor is closed when this reader closes (default is true); a file opened by this reader is always closed.
-