# Converter

While a user has an article open for editing in the Writer, it is represented in the Browser as a collection of nodes with text content and attributes. Everytime the article is to be sent or read from the article repository, it needs to be translated to an XML representation. The XML document structure for an article is well defined by the [newsitem-text.xml](https://github.com/Infomaker/writer-format/blob/master/newsml/newsitem/newsitem-text.xml) format specification.

The process of converting to/from nodes and XML is done by Writer, but it takes help from one or many converters. Example of plugins that provide converters are plugins that contribute content to the article text, or add metadata information about the article.

![](/files/-LtZo4y3ud-KNOJLLqqy)

*Conversion process from XML document to nodes in Browser*

## Telling Writer about your converter

The way to tell Writer that there's a converter to be used for a plugin, is to register it in the `package file` for the plugin. [Read more about the Package file](/writer/6.3.3/developer-guide/writer-plugin-building-blocks/package.md). In the example below, a plugin with the name `plugin` is registering a converter that is defined in the `MyPluginConverter.js` file

```javascript
// MyPluginPackage.js

import {converter} from './MyPluginConverter'

export default {
    name: 'myplugin',
    id: 'com.example.myplugin',
    version: '1.0.0',
    configure(configurator) {
        configurator.addConverter('newsml', converter)
    }
}
```

The converter should contain a function for converting data from XML to Substance Nodes, called `import`, and one function for converting from Substance Nodes to XML, called `export`. Here's an example where the plugin called `myplugin` is adding content to the article, through the `object` extension in the writer format. In this example, the plugin implements an object where it is possible to define a question and provide an answer.

The converter can also contain a function `matchElement`, to let it know if it's responsible for the current node.

```javascript
// MyPluginConverter.js

const MyPluginConverter = {
    type: 'myplugin',
    tagName: 'object',

    matchElement: function (el) {
        return el.is('object') && el.attr('type') === 'myplugin'
    },

    /**
     * Responsible for converting data from XML to a node in Browser
     */
    import: function (xmlElement, node) {
        node.question = xmlElement.attr('question')
        node.answer = xmlElement.attr('answer')
    },

    /**
     * Responsible for converting data from nodes to XML
     */
    export: function(node, xmlElement) {
        xmlElement.attr({
            question: node.question,
            answer: node.answer
        })
    }
}

export {MyPluginConverter}
```

An article example with the plugin1 active could look like:

```markup
<!-- In this interview series, we have found that the number one answer to our specific question is: -->
<object type="myplugin" question="Do you like hotdogs?" answer="yes, I do"/>
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.navigaglobal.com/writer/6.3.3/developer-guide/writer-plugin-building-blocks/converter.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
