dss/src/main/java/gov/samhsa/c2s/dss/service/EmbeddedElementExtractor.java
default String extractEmbeddedElement(String sourceXml, String xPathExprEmbeddedElement) {
        try {
            final DocumentXmlConverter documentXmlConverter = getDocumentXmlConverter();
            final DocumentAccessor documentAccessor = getDocumentAccessor();
            final Document sourceDocument = documentXmlConverter.loadDocument(sourceXml);
            final Node embeddedElement = documentAccessor.getNode(sourceDocument, xPathExprEmbeddedElement)
                    .orElseThrow(() -> new DocumentSegmentationException("Embedded Element does not exist in the Source XML"));

            // Create new document
            final Document newXmlDocument = DocumentBuilderFactory.newInstance()
                    .newDocumentBuilder().newDocument();
            // Import ClinicalDocument node to the new document
            final Node copyNode = newXmlDocument.importNode(
                    embeddedElement, true);
            // Add ClinicalDocument node as the root node to the document
            newXmlDocument.appendChild(copyNode);
            return documentXmlConverter.convertXmlDocToString(newXmlDocument);
        } catch (XPathExpressionException | ParserConfigurationException
                | DocumentXmlConverterException e) {
            throw new DocumentSegmentationException(e);
        }
    }
/**
     * Extracts an embedded element from a {@code sourceXml} and returns as a separate standalone XML
     *
     * @return extracted embedded xml
     */
Extracts an embedded element from a  sourceXml and returns as a separate standalone XML
@return extracted embedded xml
Extracts an embedded element from a sourceXml and returns as a separate standalone XML @return extracted embedded xml
default String extractEmbeddedElement(String sourceXml, String xPathExprEmbeddedElement) {
        try {
            final DocumentXmlConverter documentXmlConverter = getDocumentXmlConverter();
            final DocumentAccessor documentAccessor = getDocumentAccessor();
            final Document sourceDocument = documentXmlConverter.loadDocument(sourceXml);
            final Node embeddedElement = documentAccessor.getNode(sourceDocument, xPathExprEmbeddedElement)
                    .orElseThrow(() -> new DocumentSegmentationException("Embedded Element does not exist in the Source XML"));
            final Document newXmlDocument = DocumentBuilderFactory.newInstance()
                    .newDocumentBuilder().newDocument();
            final Node copyNode = newXmlDocument.importNode(
                    embeddedElement, true);
            newXmlDocument.appendChild(copyNode);
            return documentXmlConverter.convertXmlDocToString(newXmlDocument);
        } catch (XPathExpressionException | ParserConfigurationException
                | DocumentXmlConverterException e) {
            throw new DocumentSegmentationException(e);
        }
    }
default String extractEmbeddedElement ( String sourceXml , String xPathExprEmbeddedElement ) { try { final DocumentXmlConverter documentXmlConverter = getDocumentXmlConverter ( ) ; final DocumentAccessor documentAccessor = getDocumentAccessor ( ) ; final Document sourceDocument = documentXmlConverter . loadDocument ( sourceXml ) ; final Node embeddedElement = documentAccessor . getNode ( sourceDocument , xPathExprEmbeddedElement ) . orElseThrow ( ( ) -> new DocumentSegmentationException ( "Embedded Element does not exist in the Source XML" ) ) ; final Document newXmlDocument = DocumentBuilderFactory . newInstance ( ) . newDocumentBuilder ( ) . newDocument ( ) ; final Node copyNode = newXmlDocument . importNode ( embeddedElement , true ) ; newXmlDocument . appendChild ( copyNode ) ; return documentXmlConverter . convertXmlDocToString ( newXmlDocument ) ; } catch ( XPathExpressionException | ParserConfigurationException | DocumentXmlConverterException e ) { throw new DocumentSegmentationException ( e ) ; } }
Extracts an embedded element from a {@code sourceXml} and returns as a separate standalone XML
 @return extracted embedded xml
Extracts an embedded element from a { @code sourceXml } and returns as a separate standalone XML @return extracted embedded xml
// Create new document // Import ClinicalDocument node to the new document // Add ClinicalDocument node as the root node to the document