|
| 1 | +# XML File Paths Features |
| 2 | + |
| 3 | +XML file path support provides the capability to mark a DOM node (attribute or text) as file path with the `xml.filePathSupport.mappings` setting, by using XPath expression : |
| 4 | + |
| 5 | + * `path/text()` defines the text node of the `path` element. |
| 6 | + * `item/@path` defines the `path` attribute node of the `item` element. |
| 7 | + |
| 8 | +Once the DOM node is designated as a file path, you will enjoy the benefits of file completion. |
| 9 | + |
| 10 | + * Files completion. |
| 11 | + |
| 12 | +## Define File path in Text Content with `path/text()` |
| 13 | + |
| 14 | +Given this XML file `items.xml` sample: |
| 15 | + |
| 16 | +```xml |
| 17 | +<?xml version="1.0" encoding="utf-8"?> |
| 18 | +<items> |
| 19 | + <path>path/to/file.xml</path> |
| 20 | +</items> |
| 21 | +``` |
| 22 | + |
| 23 | +In this example: |
| 24 | + |
| 25 | +The text within the `path` tag element `<path>path/to/file.xml</path>` represents a file path. The [vscode-xml](https://github.com/redhat-developer/vscode-xml) extension offers file path support through the `xml.filePathSupport.mappings` settings. You can configure this setting as follows: |
| 26 | + |
| 27 | +```json |
| 28 | +"xml.filePathSupport.mappings": [ |
| 29 | + { |
| 30 | + "pattern": "**/items.xml", |
| 31 | + "expressions": [ |
| 32 | + { |
| 33 | + "xpath": "items/path/text()" |
| 34 | + } |
| 35 | + ] |
| 36 | + } |
| 37 | +] |
| 38 | +``` |
| 39 | + |
| 40 | +After saving this setting, you will get file path completion support for the text node of `path` tag element: |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | +## Define File path in Attribute with `item/@path` |
| 45 | + |
| 46 | +Attribute values may also be marked as file path by using the proper XPath. |
| 47 | + |
| 48 | +Given this `items.xml` XML file: |
| 49 | + |
| 50 | +```xml |
| 51 | +<?xml version="1.0" encoding="utf-8"?> |
| 52 | +<items> |
| 53 | + <item path="path/to/file.xml" ></item> |
| 54 | +</items> |
| 55 | + |
| 56 | +``` |
| 57 | + |
| 58 | +You can declare this settings: |
| 59 | + |
| 60 | +```json |
| 61 | +"xml.filePathSupport.mappings": [ |
| 62 | + { |
| 63 | + "pattern": "**/items.xml", |
| 64 | + "expressions": [ |
| 65 | + { |
| 66 | + "xpath": "item/@path" |
| 67 | + } |
| 68 | + ] |
| 69 | + } |
| 70 | +] |
| 71 | +``` |
| 72 | + |
| 73 | +After saving this setting, you will get file path completion support for the text node of `path` attribute: |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | +## Filter the file path completion result |
| 78 | + |
| 79 | +Given this `images.xml` file: |
| 80 | + |
| 81 | +```xml |
| 82 | +<items> |
| 83 | + <image src="" /> |
| 84 | +</items> |
| 85 | +``` |
| 86 | + |
| 87 | +If you need to restrict file path completion on `image/@src` files with the `.png`, `.gif` or `.jpg` extensions, you can use the `filter` property, with this settings: |
| 88 | + |
| 89 | +```json |
| 90 | +"xml.filePathSupport.mappings": [ |
| 91 | + { |
| 92 | + "pattern": "**/images.xml", |
| 93 | + "expressions": [ |
| 94 | + { |
| 95 | + "xpath": "image/@src", |
| 96 | + "filter": [".png", ".gif", ".jpg"] |
| 97 | + } |
| 98 | + ] |
| 99 | + } |
| 100 | +] |
| 101 | +``` |
| 102 | + |
| 103 | +## Separator to declare multiple file paths. |
| 104 | + |
| 105 | +Given this `paths.xml` file: |
| 106 | + |
| 107 | +```xml |
| 108 | +<items> |
| 109 | + <item paths="path/to/file1.xml;path/to/file2.xml" /> |
| 110 | +</items> |
| 111 | +``` |
| 112 | + |
| 113 | +If you want to handle file path completion for `item/@paths` by declaring several file paths separated by `;`, you can use the `separator` property with these settings: |
| 114 | + |
| 115 | +```json |
| 116 | +"xml.filePathSupport.mappings": [ |
| 117 | + { |
| 118 | + "pattern": "**/paths.xml", |
| 119 | + "expressions": [ |
| 120 | + { |
| 121 | + "xpath": "item/@paths", |
| 122 | + "separator": ";" |
| 123 | + } |
| 124 | + ] |
| 125 | + } |
| 126 | +] |
| 127 | +``` |
0 commit comments