Skip to content

XmlNode.Format

Overview

String XmlNode.Format ( template, [ options ] )
Returns result of specified template on current node.

Arguments

String template Template to apply.

Object options Template options. Can be null. Option contains the parameters to be used in template or following properties:

String Culture Culture to use on converting date or numeric values.

Remarks

Like XSLT formatting this method provides much simpler template usage for converting XML data to HTML or any other data.

Template may contain xpath expressions or variables that wrapped in {{ and }} characters. All formatting done with invariant culture if not specified in options. Please refer the Data Templates section for more information.

Custom variables can be used in template content as {{VariableName}} format. If variable is an object; formatting string can be used as {{VariableName.Property}}.

Examples

Basic template

var myNode = $Xml.Parse("<Customer><Name>John</Name></Customer");
var result = myNode.Format('<p>Hello {{Customer/Name}}!</p>');
// result now contains "<p>Hello John!</p>"

Date formatting

var myNode = $Xml.Parse("<Customer><Name>John</Name><BirthDate>2014-01-31T09:00:00+02:00</BirthDate></Customer");
var result = myNode.Format('<p>Birth date : {{Customer/BirthDate}}</p>');
// result now contains "<p>Birth date : 01/31/2014 09:00:00 +02:00</p>"

Using variable

var myNode = $Xml.Parse("<Customer><Name>John</Name><BirthDate>2014-01-31T09:00:00+02:00</BirthDate></Customer");
var result = myNode.Format('<p>{{$MyVariable}}</p>', {
  MyVariable : 'Custom Variable'
});
// result: <p>Custom Variable</p>

See Also