# Extract text structure Extract the text structure of a document as an XML document and process it with GroupDocs.Parser for Node.js via Java. GroupDocs.Parser provides the functionality to extract the text structure from documents by the `getStructure` method: ```javascript parser.getStructure(); // returns an org.w3c.dom.Document object or null ``` This method returns the XML representation of a document as a Java `org.w3c.dom.Document` object. You work with it through the standard Java DOM methods (`getDocumentElement()`, `getChildNodes()`, `getNodeName()`, `getAttributes()` and so on). A document has the following structure: ![](https://docs.groupdocs.com/parser/nodejs-java/images/extract-text-structure.png) | Tag | Description | | --- | --- | | document | The root tag | | section | Represents a section of the document. Depending on the document type, it can represent a worksheet, a slide and so on. Can contain the following attributes: | | p | Represents a text paragraph. Can contain the following attribute: | | ul | Represents an unordered list | | ol | Represents an ordered list | | li | Represents a list item | | shape | Represents a shape object. | | table | Represents a table | | tr | Represents a table row | | td | Represents a table cell. Can contain the following attributes: | Tags have the following relations: * **document** tag can contain any number of **section** tags * **section** tag can contain any number of **p, ul, ol** or **table** tags in any sequence * **table** tag can contain any number of **tr** tags * **tr** tag can contain any number of **td** tags * **td** tag can contain one **p** tag The **p** and **li** tags can contain **hyperlink, strong, em** tags and the value that represents a text: ![](https://docs.groupdocs.com/parser/nodejs-java/images/extract-text-structure_1.png)![](https://docs.groupdocs.com/parser/nodejs-java/images/extract-text-structure_2.png) | Tag | Description | | --- | --- | | hyperlink | Represents a hyperlink. Can contain the following attribute: | | strong | Represents a strong emphasis (bold text) | | em | Represents a regular emphasis (italic text) | | br | Represents a line break (empty tag) | ## Features of text extraction for different formats ### Word processing documents Word processing documents have a more complex table cell, and a paragraph can contain any number of shapes. A table cell can contain any number of paragraphs, lists and tables: ![](https://docs.groupdocs.com/parser/nodejs-java/images/extract-text-structure_3.png) A shape can contain a single hyperlink (empty tag) for the entire shape and any number of paragraphs, lists or tables: ![](https://docs.groupdocs.com/parser/nodejs-java/images/extract-text-structure_4.png) ### Presentations Presentations have a more complex table cell, and a section can contain any number of shapes. A table cell can contain any number of paragraphs or lists: ![](https://docs.groupdocs.com/parser/nodejs-java/images/extract-text-structure_5.png) A shape can contain a single hyperlink (empty tag) for the entire shape and any number of paragraphs or lists: ![](https://docs.groupdocs.com/parser/nodejs-java/images/extract-text-structure_6.png) ### Spreadsheets Spreadsheets have the following document structure: ![](https://docs.groupdocs.com/parser/nodejs-java/images/extract-text-structure_7.png) It's simpler than the others. A section can contain any number of shapes and only one table. A shape can contain a single hyperlink (empty tag) for the entire shape and any number of paragraphs. ## Examples Here are the steps to extract hyperlinks from the document: * Instantiate the `Parser` object for the initial document; * Call the `getStructure` method and obtain the `org.w3c.dom.Document` object; * Check if `document` isn't `null` (text structure extraction is supported for the document); * Process the XML document. The following example shows how to extract hyperlinks from the document: ```javascript const groupdocs = require('@groupdocs/groupdocs.parser'); // Recursively print the "link" attribute of all hyperlink nodes function readNode(node) { const nodes = node.getChildNodes(); for (let i = 0; i < nodes.getLength(); i++) { const n = nodes.item(i); if (n.getNodeName().toLowerCase() === 'hyperlink') { const a = n.getAttributes().getNamedItem('link'); if (a != null) { console.log(a.getNodeValue()); } } if (n.hasChildNodes()) { readNode(n); } } } // Create an instance of Parser class const parser = new groupdocs.Parser('Hyperlinks.docx'); try { // Extract text structure as an XML document (org.w3c.dom.Document) const document = parser.getStructure(); // Check if text structure extraction is supported if (document == null) { console.log("Text structure extraction isn't supported."); } else { // Read XML document readNode(document.getDocumentElement()); } } finally { parser.close(); } process.exit(0); ``` The following document: ![](https://docs.groupdocs.com/parser/nodejs-java/images/extract-text-structure_8.png) has the following text structure: ```xml

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa.

Lorem

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna.

  1. Nunc viverra imperdiet enim.
  2. Fusce est.

Vivamus a tellus.

In porttitor.

Donec laoreet nonummy augue.

Suspendisse dui purus, scelerisque at, vulputate vitae, pretium mattis, nunc.

Mauris eget neque at sem venenatis eleifend.

Ut nonummy.

Fusce aliquet pede non pede.

Suspendisse dapibus lorem pellentesque magna.

Integer nulla.

Donec blandit feugiat ligula.

Donec hendrerit, felis et imperdiet euismod, purus ipsum pretium metus, in lacinia nulla nisl eget sapien.

Donec ut est in lectus consequat consequat.

Etiam eget dui. Aliquam erat volutpat.

Sed at lorem in nunc porta tristique. Proin nec augue.

``` ## More resources ### Free online document parser App Along with the full-featured library we provide simple but powerful free apps. You are welcome to extract data from PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX, Emails and more with our [Free Online Document Parser App](https://products.groupdocs.app/parser).