# How use xmlLinter?

**URL:** <https://discuss.codemirror.net/t/how-use-xmllinter/6985>\
**Category:** v6\
**Created:** [August 14, 2023, 12:16pm UTC](https://discuss.codemirror.net/t/how-use-xmllinter/6985 "2023-08-14T12:16:03Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andr](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/andr/32/3638_2.png) [@Andr](https://discuss.codemirror.net/u/Andr)\
**Post date:** [August 14, 2023, 12:16pm UTC](https://discuss.codemirror.net/t/how-use-xmllinter/6985/1 "2023-08-14T12:16:03Z")

</div>

Hello!  
How use xmlLinter? We have @codemirror/lang-xml, but have not ParseLinter.  
Example: @codemirror/lang-json - jsonParseLinter and I use in extension - linter(jsonParseLinter()).

Can someone provide a example?  
Thank you

---

<div class="post-metadata">

**Author:** ![marijn](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/marijn/32/136_2.png) [@marijn](https://discuss.codemirror.net/u/marijn)\
**Post date:** [August 15, 2023, 8:07pm UTC](https://discuss.codemirror.net/t/how-use-xmllinter/6985/2 "2023-08-15T20:07:00Z")

</div>

@codemirror/lang-xml does not come with a linter (everything it exports is listed in the readme, so if you don’t find it there, its not in the package).

---

<div class="post-metadata">

**Author:** ![Andr](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/andr/32/3638_2.png) [@Andr](https://discuss.codemirror.net/u/Andr)\
**Post date:** [August 16, 2023, 9:33am UTC](https://discuss.codemirror.net/t/how-use-xmllinter/6985/3 "2023-08-16T09:33:41Z")

</div>

Thank you @marijn !  
Guys, who can share the experience who did the xml lint for CodeMirror v6?  
I didn’t understand - [https://develop.prosemirror.net/examples/lint/](https://develop.prosemirror.net/examples/lint/)

---

<div class="post-metadata">

**Author:** ![marijn](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/marijn/32/136_2.png) [@marijn](https://discuss.codemirror.net/u/marijn)\
**Post date:** [August 16, 2023, 11:04am UTC](https://discuss.codemirror.net/t/how-use-xmllinter/6985/5 "2023-08-16T11:04:35Z")

</div>

> [@Andr](#):
>
> I didn’t understand - [https://develop.prosemirror.net/examples/lint/](https://develop.prosemirror.net/examples/lint/)

That’s about a completely different library, so indeed, it won’t help you here. But I am curious where you got that link, since I don’t use the [develop.prosemirror.net](http://develop.prosemirror.net) domain (though the way my server is set up apparently serves up the plain [prosemirror.net](http://prosemirror.net) content on it).

---

<div class="post-metadata">

**Author:** ![Andr](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/andr/32/3638_2.png) [@Andr](https://discuss.codemirror.net/u/Andr)\
**Post date:** [August 17, 2023, 6:12am UTC](https://discuss.codemirror.net/t/how-use-xmllinter/6985/6 "2023-08-17T06:12:25Z")

</div>

@marijn , I don’t know how I found this link), when I searched the Internet, I looked at a lot of things

---

<div class="post-metadata">

**Author:** ![Andr](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/andr/32/3638_2.png) [@Andr](https://discuss.codemirror.net/u/Andr)\
**Post date:** [September 4, 2023, 8:49am UTC](https://discuss.codemirror.net/t/how-use-xmllinter/6985/7 "2023-09-04T08:49:09Z")

</div>

Hi! @marijn, I did tags check in xml. Please tell me, how to check for an open quote or equal sign?  
Thank you!

```auto
const tagLinter = linter(view => {
            let diagnostics: Diagnostic[] = []
            syntaxTree(view.state).cursor().iterate(node => {
                // No open tag
                if (node.name == "MismatchedCloseTag") {
                    let tagName = this.getTagAsString(view.state, node.from, node.to);
                    diagnostics.push({
                        from: node.from,
                        to: node.to,
                        severity: "error",
                        message: `No open tag for ${tagName}`
                    })
                }
                // No closed the tag
                if (node.name == "MissingCloseTag") {
                    // looking for the tag that led to the problem
                    let tag = node.node.parent?.firstChild;
                    let from = tag?.from;
                    let to = tag?.to;
                    let tagName = this.getTagAsString(view.state, from, to);
                    diagnostics.push({
                        from: from ? from : node.from,
                        to: to ? to : node.to,
                        severity: "error",
                        message: "No closed the tag for " + tagName
                    })
                }
            })
            return diagnostics;
        })

getTagAsString(state: EditorState, from: number | undefined, to: number | undefined): string | undefined {
        if (!from || !to) return undefined;
        return state.doc.toString().substring(from, to);
    }

```

---

<div class="post-metadata">

**Author:** ![marijn](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/marijn/32/136_2.png) [@marijn](https://discuss.codemirror.net/u/marijn)\
**Post date:** [September 4, 2023, 11:31am UTC](https://discuss.codemirror.net/t/how-use-xmllinter/6985/8 "2023-09-04T11:31:38Z")

</div>

I don’t really understand the question. Open quotes on attributes aren’t separate tree nodes, they are just part of an attribute value node.

> [@Andr](#):
>
> `return state.doc.toString().substring(from, to);`

Please don’t do this. You’re serializing a (potentially huge) document in its entirety to then take a tiny substring of it. Use `state.doc.sliceDoc(from, to)`.

---

<div class="post-metadata">

**Author:** ![Andr](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/andr/32/3638_2.png) [@Andr](https://discuss.codemirror.net/u/Andr)\
**Post date:** [September 5, 2023, 8:37am UTC](https://discuss.codemirror.net/t/how-use-xmllinter/6985/9 "2023-09-05T08:37:40Z")

</div>

Hi! @marijn, thank you

> [@Andr](#):
>
> return state.doc.toString().substring(from, to);

but i found this

```auto
return state.doc.sliceString(from, to)

```

for check quotes and “=” did so:

```auto
if (node.name == 'Attribute') {
                    const attributeName = this.getElementAsString(doc, node.from, node.to);
                    const countOfCharacterEquals = attributeName.replace(/[^=]/g, ''); // Count of '=' characters in attribute with value
                    const countOfCharacterQuotes = attributeName.replace(/[^"]/g, ''); // Count of quotes in attribute with value

                    if (countOfCharacterEquals.length === 0) {
                        this.xmlSyntaxErrors.push({
                            from: node.from,
                            to: node.to,
                            severity: 'error',
                            message: `Attribute ${attributeName} miss symbol '='`
                        });

                        return;
                    }
                    if (countOfCharacterEquals.length > 1 || countOfCharacterQuotes.length < 2) {
                        this.xmlSyntaxErrors.push({
                            from: node.from,
                            to: node.to,
                            severity: 'error',
                            message: `Have open quote ${attributeName}`
                        });
                    }

                }

```
