The last XPath query is being persisted and can be reused with the next query.
This commit is contained in:
		
							parent
							
								
									eeb0ed8d4c
								
							
						
					
					
						commit
						f3ea33a522
					
				
					 1 changed files with 22 additions and 1 deletions
				
			
		| 
						 | 
					@ -9,7 +9,8 @@ let resultChannel: OutputChannel = null;
 | 
				
			||||||
export function evaluateXPath(editor: TextEditor, edit: TextEditorEdit): void {
 | 
					export function evaluateXPath(editor: TextEditor, edit: TextEditorEdit): void {
 | 
				
			||||||
	window.showInputBox({
 | 
						window.showInputBox({
 | 
				
			||||||
		placeHolder: 'XPath Query',
 | 
							placeHolder: 'XPath Query',
 | 
				
			||||||
		prompt: 'Please enter an XPath query to evaluate.'
 | 
							prompt: 'Please enter an XPath query to evaluate.',
 | 
				
			||||||
 | 
							value: Singleton.getXPathValue()
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
	}).then((query) => {
 | 
						}).then((query) => {
 | 
				
			||||||
		if (query === undefined) return;
 | 
							if (query === undefined) return;
 | 
				
			||||||
| 
						 | 
					@ -17,6 +18,8 @@ export function evaluateXPath(editor: TextEditor, edit: TextEditorEdit): void {
 | 
				
			||||||
		let xml = editor.document.getText();
 | 
							let xml = editor.document.getText();
 | 
				
			||||||
		let doc = new dom().parseFromString(xml);
 | 
							let doc = new dom().parseFromString(xml);
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
 | 
							Singleton.setXPathValue(query);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
		try {
 | 
							try {
 | 
				
			||||||
			var nodes = xpath.select(query, doc);
 | 
								var nodes = xpath.select(query, doc);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					@ -43,3 +46,21 @@ export function evaluateXPath(editor: TextEditor, edit: TextEditorEdit): void {
 | 
				
			||||||
		resultChannel.show(ViewColumn.Three);
 | 
							resultChannel.show(ViewColumn.Three);
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Singleton {
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						class XPathContext 
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							static _lastXPathValue:string = '';
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
					    export function getXPathValue():string
 | 
				
			||||||
 | 
						{ 
 | 
				
			||||||
 | 
							 return XPathContext._lastXPathValue;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						export function setXPathValue(val:string):void 
 | 
				
			||||||
 | 
						{ 
 | 
				
			||||||
 | 
							 XPathContext._lastXPathValue = val;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue