Skip to content

Commit 0b9cd83

Browse files
angelozerrdatho7561
authored andcommitted
RelaxNG support documentation
Signed-off-by: azerr <azerr@redhat.com>
1 parent 27d2b9a commit 0b9cd83

15 files changed

Lines changed: 144 additions & 4 deletions

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ This VS Code extension provides support for creating and editing XML documents,
1919
| ------------------ | ------------------------------------------- |
2020
| enabled by default | requires additional configuration to enable |
2121

22+
* [RelaxNG (experimental) support](https://github.com/redhat-developer/vscode-xml/blob/main/docs/Features/RelaxNGFeatures#relaxng-features) (since v0.22.0)
2223
* Syntax error reporting
2324
* General code completion
2425
* [Auto-close tags](https://github.com/redhat-developer/vscode-xml/blob/main/docs/Features/XMLFeatures.md#xml-tag-auto-close)

docs/Features.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
[vscode-xml](https://github.com/redhat-developer/vscode-xml) has a number of notable features available for XML, XSD and DTD support.
44

5-
- [XML Features](Features/XMLFeatures.md#xml-features)
6-
- [XSD Features](Features/XSDFeatures.md#xsd-features)
7-
- [DTD Features](Features/DTDFeatures.md#dtd-features)
5+
- [XML features](Features/XMLFeatures.md#xml-features)
6+
- [XSD features](Features/XSDFeatures.md#xsd-features)
7+
- [DTD features](Features/DTDFeatures.md#dtd-features)
8+
- [RelaxNG features](Features/RelaxNGFeatures.md#relaxng-features)

docs/Features/RelaxNGFeatures.md

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# RelaxNG features
2+
3+
[vscode-xml](https://github.com/redhat-developer/vscode-xml) provides validation, completion, hover in XML file based on [RelaxNG schemas](https://relaxng.org/) since `0.22.0`:
4+
5+
![RelaxNG support](../images/RelaxNG/RelaxNGSupport.gif)
6+
7+
It supports both:
8+
9+
* [RelaxNG XML syntax (*.rng files)](https://relaxng.org/tutorial-20011203.html).
10+
* [RelaxNG Compact syntax (*.rnc files)](https://relaxng.org/compact-tutorial-20030326.html).
11+
12+
![XML Validated with RelaxNG](../images/RelaxNG/XMLValidatedWithRelaxNG.png)
13+
14+
You can associate your XML file with `RelaxNG grammar` (`file` or `URL`) using :
15+
16+
* an `xml-model` processing instruction
17+
18+
```xml
19+
<?xml-model href="addressBook.rng" type="application/xml"?>
20+
<addressBook>
21+
...
22+
</addressBook>
23+
```
24+
25+
* an `XML catalog` using the same method as [XSD](Validation#XML-catalog-with-XSD)
26+
* a `file association` using the same method as [XSD](Validation#XML-file-association-with-xsd)
27+
28+
## RelaxNG grammar
29+
30+
[vscode-xml](https://github.com/redhat-developer/vscode-xml) provides support for `RelaxNG grammars`:
31+
32+
* for [RelaxNG XML syntax (*.rng files)](https://relaxng.org/tutorial-20011203.html), it provides the same support as XSD/DTD grammars (completion, hover, validation, etc).
33+
34+
![RelaxNG XML Syntax Overview](../images/RelaxNG/RelaxNGXMLSyntaxOverview.png)
35+
36+
* for [RelaxNG Compact syntax (*.rnc files)](https://relaxng.org/compact-tutorial-20030326.html) it provides only syntax coloration.
37+
38+
![RelaxNG Compact Syntax Overview](../images/RelaxNG/RelaxNGCompactSyntaxOverview.png)
39+
40+
# Validation
41+
42+
XML validation based on RelaxNG (rng, rnc) is supported:
43+
44+
![RelaxNG Validation](../images/RelaxNG/RelaxNGValidation.png)
45+
46+
# Completion
47+
48+
XML completion based on RelaxNG (rng, rnc) is supported. The completion for rng can show the documentation:
49+
50+
![RelaxNG Completion And Documentation](../images/RelaxNG/RelaxNGCompletionAndDocumentation.png)
51+
52+
# Hover
53+
54+
Hover based on RelaxNG rng can show the documentation:
55+
56+
![RelaxNG Hover And Documentation](../images/RelaxNG/RelaxNGHoverAndDocumentation.png)
57+
58+
# Go to Type Definition
59+
60+
From the XML document you can go to the type definition to navigate to the element/attribute declaration for both `rnc` and `rng`.
61+
62+
To do this, select an XML element/attribute and use the contextual menu `Go to Type Definition`:
63+
64+
![Go to Type Definition Menu](../images/RelaxNG/GoToTypeDefinitionMenu.png)
65+
66+
When you click on this menu item, VS Code will open the `rng` or `rnc` grammar file and place the cursor on the proper `element/attribute` declaration:
67+
68+
![Go to Type Definition result](../images/RelaxNG/GoToTypeDefinitionResult.png)
69+
70+
# How to start?
71+
72+
## Using snippets
73+
74+
You can use snippets to quickly create:
75+
76+
* an XML file associated with a RelaxNG grammar
77+
* a RelaxNG XML file
78+
79+
Here's a demo:
80+
81+
![RelaxNG snippets support](../images/RelaxNG/RelaxNGSnippetsSupport.gif)
82+
83+
## Creating XML, rng, rnc files
84+
85+
You can create a RelaxNG grammar that uses the XML syntax by making a file with the extension `.rng`.
86+
For instance, here is a file `addressBook.rng` that defines a RelaxNG grammar:
87+
88+
```xml
89+
<?xml version="1.0" encoding="UTF-8"?>
90+
<grammar xmlns="http://relaxng.org/ns/structure/1.0">
91+
<start>
92+
<element name="addressBook">
93+
<zeroOrMore>
94+
<element name="card">
95+
<ref name="cardContent"/>
96+
</element>
97+
</zeroOrMore>
98+
</element>
99+
</start>
100+
<define name="cardContent">
101+
<element name="name">
102+
<text/>
103+
</element>
104+
<element name="email">
105+
<text/>
106+
</element>
107+
</define>
108+
</grammar>
109+
```
110+
111+
You can create a RelaxNG grammar that uses the [compact syntax](https://relaxng.org/compact-tutorial-20030326.html) by making a file with the extension `.rnc`.
112+
For instance, here is a file `addressBook.rnc` that defines the same RelaxNG grammar as `addressBook.rng`:
113+
114+
```rnc
115+
element addressBook {
116+
element card {
117+
element name { text },
118+
element email { text }
119+
}*
120+
}
121+
```
122+
123+
The following file, `addressBook.xml`, references `addressBook.rng` using the `xml-model` processing instruction.
124+
[vscode-xml](https://github.com/redhat-developer/vscode-xml) will provide the features based on the grammar shown in [the demo at the beginning of this page](#relaxng-support) when you open `addressBook.xml`.
125+
126+
```xml
127+
<?xml-model href="addressBook.rng" type="application/xml"?>
128+
<addressBook>
129+
<card>
130+
<name></name>
131+
<email></email>
132+
</card>
133+
</addressBook>
134+
```

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Welcome to the [vscode-xml](https://github.com/redhat-developer/vscode-xml) docu
44

55
## User Guide
66

7-
* [XML Validation](Validation.md#xml-validation): How to validate XML with a grammar (XSD/DTD)?
7+
* [XML Validation](Validation.md#xml-validation): How to validate XML with a grammar (XSD/DTD/RelaxNG)?
88
* [Preferences](Preferences.md#preferences): More info on available [vscode-xml](https://github.com/redhat-developer/vscode-xml) preferences.
99
* [Formatting](Formatting.md#formatting): More info on the available formatting preferences.
1010
* [XML Commands](Commands.md#commands): More info on the available XML vscode commands.

docs/Validation.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,10 @@ If one of the variables for an association can't be expanded (eg. because vscode
399399
the association is ignored.
400400
This feature is specific to the VSCode client.
401401

402+
## Validation with RelaxNG grammar
403+
404+
See [RelaxNG features](Features/RelaxNGFeatures#relaxng-features)
405+
402406
# Other Validation Settings
403407

404408
## Disallow Doc Type Declarations
20.4 KB
Loading
30.1 KB
Loading
8.11 KB
Loading
41.9 KB
Loading
19.5 KB
Loading

0 commit comments

Comments
 (0)