Create HTML using HtmlTextWriter class in x++

HtmlTextWriter class is used to output properly formed HTML
into a web page.  The
HtmlTextWriter allows the developer to code attributes, style attributes, and
tags etc.

The HtmlTextWriter class permits the developer to generate
page output in a non-browser specific way; that is to say, the burden of
developing alternative markup is typically removed by using the
HtmlTextWriter.  The HtmlTextWriter class exposes properties, fields, and
methods that permit the developer to format HTML 4.0 compliant output. 

For example, in the job below i  added static string and  an image using the HtmlTextWriter class.

static void HTMLTextWriter(Args _args)

{

    HTMLTextWriter htw = new HTMLTextWriter();

    TextBuffer     txtBuffer = new TextBuffer();

    CCHTMLString   staticString;

    ;

    staticString = @’At
Solugenix we know our success results from taking a long term view in all

    our relationships: clients,
employees, industries and technologies.’;

   
htw.renderBeginTag(HtmlTextWriterTag::table());

   
htw.renderBeginTag(HtmlTextWriterTag::tr());

   
htw.write(staticString);

   
htw.addAttribute(HtmlTextWriterAttribute::class_Attribute(), ‘ms-vb’);

   
htw.addStyleAttribute(HtmlTextWriterStyle::width(), ’26px’);

   
htw.addStyleAttribute(HtmlTextWriterStyle::padding_top(), ‘3px’);

   
htw.renderBeginTag(HtmlTextWriterTag::td());

   
htw.addAttribute(HtmlTextWriterAttribute::src(), ‘http://www.holidayegreetingssite.com/index_files/image3121.jpg’);//get
the image from web

   
htw.addStyleAttribute(HtmlTextWriterStyle::width(), ‘100’);

   
htw.addStyleAttribute(HtmlTextWriterStyle::height(), ’50’);

   
htw.renderBeginTag(HtmlTextWriterTag::img(), true);

    htw.renderEndTag();
//close <Td>

    htw.renderEndTag();
//close <Table>

   
txtBuffer.setText(htw.getHtmlString());

   
txtBuffer.toFile(‘f:\\DynamicsAX.html’);  // please provide your path to save the
file

}

The result of the above code will be –

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: