angular-xml-editor
Version:
XML editor component for Angular
107 lines (82 loc) • 3.46 kB
Markdown
#Angular XML editor
XML editor component for Angular
## Screenshot

## Usage
Html view
```html
<axed-editor [debugMode]="true" [editorContextId]="editorContextId" [(ngModel)]="xmlContent"></axed-editor>
```
Typescript code behind
```javascript
_xmlContent: string;
get xmlContent(): string {
return this._xmlContent;
}
set xmlContent(value: string) {
this._xmlContent = value;
}
editorContextId: string;
editorContext: XmlEditorContext;
public config: XmlEditorConfig = undefined;
public contentLoaded = false;
constructor(private _http: HttpClient, private editorService: AngularXmlEditorService) {
this.editorContextId = this.editorService.getNewEditorContextId();
this.editorContext = this.editorService.getEditorContext(this.editorContextId);
}
ngOnInit(): void {}
ngAfterContentInit(): void {
const xmlFile = '/assets/demoContent.xml';
const xsdFile = '/assets/demoSchema.xsd';
const main = async () => {
const xml = await this._http.get(xmlFile, { responseType: 'text' }).toPromise();
const xsd = await this._http.get(xsdFile, { responseType: 'text' }).toPromise();
const floatingElementNames = ['br', 'set', 'think', 'srai', 'person', 'person2', 'star'];
const xmlSchema = new XmlSchemaLoader(xsd).xmlSchema;
const rules = new XmlRulesCreator(xmlSchema, floatingElementNames).rules;
const groups = [
{
id: 'html',
title: 'html',
elementNames: ['a', 'br', 'p', 'table', 'td', 'tr', 'img']
},
{
id: 'pro',
title: 'pro',
elementNames: ['script']
}
] as XmlRuleElementGroup[];
this.config = {
rules: rules,
xmlSchema: xmlSchema,
elementGroups: groups,
spellcheck: true,
height: '40vh',
minHeight: '10vh'
} as XmlEditorConfig;
this.editorContext.config = this.config;
this.xmlContent = xml;
this.contentLoaded = true;
};
main();
}
```
## Licence
MIT License
Copyright (c) 2019 Daniel Springwald, daniel@springwald.de, blog.springwald.de
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.