# Html formatting in an xml document

**URL:** <https://forum.kirupa.com/t/html-formatting-in-an-xml-document/177695>\
**Category:** Uncategorized\
**Created:** [February 4, 2006, 5:12am UTC](https://forum.kirupa.com/t/html-formatting-in-an-xml-document/177695 "2006-02-04T05:12:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Inept](https://avatars.discourse-cdn.com/v4/letter/i/e274bd/32.png) [@Inept](https://forum.kirupa.com/u/Inept)\
**Post date:** [February 4, 2006, 5:12am UTC](https://forum.kirupa.com/t/html-formatting-in-an-xml-document/177695/1 "2006-02-04T05:12:24Z")

</div>

Hi guys,

I’ve been trying to figure out a way to use html formatting inside an xml document and have accomplished it, but the only problem is that _undefined_ is displayed before the text???

So the final result when I test the flash file is:  
_undefined_ **This is bold text**

How it works is the html tags in the xml document are written using the [brackets instead. The function searches through the selected node(s) and converts the [] to \<\>

Heres the code:  
ActionScript Code:  
[FONT=Courier New][LEFT][COLOR=#000000] **function** [/COLOR] xmlTagsCOLOR=#000000[/COLOR]  
[COLOR=#000000]{[/COLOR]  
[COLOR=#000000] **var** [/COLOR] i;  
[COLOR=#000000] **var** [/COLOR] contents;  
[COLOR=#0000ff]for[/COLOR] [COLOR=#000000]([/COLOR]i = [COLOR=#000080]0[/COLOR]; i \< [COLOR=#0000ff]xml[/COLOR].[COLOR=#0000ff]length[/COLOR]; i++[COLOR=#000000])[/COLOR]  
[COLOR=#000000]{[/COLOR]  
tags = [COLOR=#0000ff]xml[/COLOR].[COLOR=#0000ff]charAt[/COLOR]COLOR=#000000[/COLOR];  
[COLOR=#0000ff]if[/COLOR] [COLOR=#000000]([/COLOR]tags == [COLOR=#ff0000]"["[/COLOR][COLOR=#000000])[/COLOR]  
[COLOR=#000000]{[/COLOR]  
tags = [COLOR=#ff0000]"\<"[/COLOR];  
[COLOR=#000000]}[/COLOR]  
[COLOR=#0000ff]else[/COLOR] [COLOR=#0000ff]if[/COLOR] [COLOR=#000000]([/COLOR]tags == [COLOR=#ff0000]"]"[/COLOR][COLOR=#000000])[/COLOR]  
[COLOR=#000000]{[/COLOR]  
tags = [COLOR=#ff0000]"\>"[/COLOR];  
[COLOR=#000000]}[/COLOR] [COLOR=#808080]_// end if_[/COLOR]  
contents = contents + tags;  
[COLOR=#000000]}[/COLOR] [COLOR=#808080]_// end of for_[/COLOR]  
[COLOR=#0000ff]return[/COLOR]COLOR=#000000[/COLOR];  
[COLOR=#000000]}[/COLOR] [COLOR=#808080]_// End of the function_[/COLOR]

[COLOR=#000000] **function** [/COLOR] loadXMLCOLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000ff]if[/COLOR] COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
loadXML = [COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]firstChild[/COLOR];  
title = [COLOR=#000000][[/COLOR][COLOR=#000000]][/COLOR];  
total = loadXML.[COLOR=#0000ff]childNodes[/COLOR].[COLOR=#0000ff]length[/COLOR]  
p = [COLOR=#000080]0[/COLOR];

```
    [COLOR=#0000ff]for[/COLOR] [COLOR=#000000]([/COLOR]i=[COLOR=#000080]0[/COLOR]; i&lt;total; i++[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
        title[COLOR=#000000][[/COLOR]i[COLOR=#000000]][/COLOR] = xmlTags[COLOR=#000000]([/COLOR]loadXML.[COLOR=#0000ff]childNodes[/COLOR][COLOR=#000000][[/COLOR]i[COLOR=#000000]][/COLOR].[COLOR=#0000ff]childNodes[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000080]0[/COLOR][COLOR=#000000]][/COLOR].[COLOR=#0000ff]firstChild[/COLOR].[COLOR=#0000ff]nodeValue[/COLOR][COLOR=#000000])[/COLOR];
    [COLOR=#000000]}[/COLOR]
    
    words[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
    
[COLOR=#000000]}[/COLOR] [COLOR=#0000ff]else[/COLOR] [COLOR=#000000]{[/COLOR]
    [COLOR=#0000ff]trace[/COLOR][COLOR=#000000]([/COLOR][COLOR=#ff0000]"xml document failed to load"[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#000000]}[/COLOR]

```

[COLOR=#000000]}[/COLOR]  
[COLOR=#000000] **function** [/COLOR] wordsCOLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]

```
title_txt.[COLOR=#0000ff]htmlText[/COLOR] = title[COLOR=#000000][[/COLOR][COLOR=#000080]0[/COLOR][COLOR=#000000]][/COLOR];

```

[COLOR=#000000]}[/COLOR]

xmlData = [COLOR=#000000] **new** [/COLOR] [COLOR=#0000ff]XML[/COLOR]COLOR=#000000[/COLOR];  
xmlData.[COLOR=#0000ff]ignoreWhite[/COLOR] = [COLOR=#000000] **true** [/COLOR];  
xmlData.[COLOR=#0000ff]onLoad[/COLOR] = loadXML;  
xmlData.[COLOR=#0000ff]load[/COLOR]COLOR=#000000[/COLOR];  
[/LEFT]  
[/FONT]

Heres the xml document:

```auto
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<stuff>
    <things>
        <words>[b]This is bold text[/b]</words>
    </things>
</stuff>

```

The spaces between the [] are there so the “this is bold text” won’t actually go bold on the forum, there are no spaces in the original xml document.

Cheers,  
_-Inept_
