A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: namespaces in xml for html markup

  1. #1
    will i ever get it?
    Join Date
    Feb 2004
    Posts
    707

    namespaces in xml for html markup

    hi, we have an xml file we will be loading into a project. The xml will be littered with AS3 friendly styling (inline) but we were hoping to avoid the ugly CDATA--ie:
    Code:
     <![CDATA[<p>This is text</p>]]>
    The approach we are hoping to accomplish would be declaring a namespace in the xml:

    Code:
    <pages>
    		<page>
    			<content xmlns:h="http://www.w3.org/1999/xhtml">
    				<text targetid="1">
    					<h:font color='#ffffff'>This text</h:font>will go into the box with id of 1.
    				</text>
    				<text targetid="2">
    					This text will go into the box with id of 2.
    				</text>
    			</content>
    		</page>
    </pages>
    i know there is a Namespace class, but i am not sure how to tie the two together....can someone give me a lead? I have read this , but it does not lead me to the connection with how this MAY work with html...if at all.

  2. #2
    will i ever get it?
    Join Date
    Feb 2004
    Posts
    707
    still no takers?

  3. #3
    will i ever get it?
    Join Date
    Feb 2004
    Posts
    707
    well, for those who stumble on this, or those who want a shot at it...my workaround was this. I declared the namespace as norm by w3c to escape ugly CDATA calls:
    Code:
    <pages>
    		<page>
    			<content xmlns:h="http://www.w3.org/1999/xhtml">
    				<text targetid="1">
    					<h:font color='#ffffff'>This text</h:font>will go into the box with id of 1.
    				</text>
    				<text targetid="2">
    					This text will go into the box with id of 2.
    				</text>
    			</content>
    		</page>
    </pages>
    however, this created results like:
    Code:
    <h:font color="#ffffff" xmlns:h="http://www.w3.org/TR/html4/">This text</h:font>
    this resulted in a nicely read xml without an error, but the html was not rendering. My workaorund was a regex that strips out the xmlns:h=... attribute in the tags, as well as any <h: or any </h:.
    Code:
    var htmltx:String=page_content.text_copy[i].children().toString();//the xml with namespaces
    var strip_open_h:RegExp=/(\<h:)/g;
    var strip_close_h:RegExp=/(\<\/h:)/g; 
    var wo_h=htmltx.replace(strip_open_h,'<');
    var woo_h=wo_h.replace(strip_close_h,'</'); 
    var remove_ns:RegExp=/(xmlns:h="http:\/\/www.w3.org\/TR\/html4\/")/g;
    var fin=woo_h.replace(remove_ns,"")
    //traces <font color="#ffffff" >This text</font>
    Looks clean in the xml, but perhaps more work than it was worth...Any other ideas?

  4. #4
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,361
    You want to get only the element and contents of the tag with the namespace specified?

  5. #5
    will i ever get it?
    Join Date
    Feb 2004
    Posts
    707
    Quote Originally Posted by senocular
    You want to get only the element and contents of the tag with the namespace specified?
    Exactly! Got an approach?

  6. #6
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,361
    well regex is certainly not a pretty way to go about it. You can get the elements you want through sorting, and a simple for loop can let you strip the namespace from each element:

    PHP Code:
    var ns:Namespace = new Namespace("h""http://www.w3.org/1999/xhtml");
    var list:
    XMLList pages.descendants().(namespace() == ns);
    for 
    each (var elem:XML in list) elem.setNamespace("");
    yourTextField.htmlText = list.toXMLString(); 

  7. #7
    will i ever get it?
    Join Date
    Feb 2004
    Posts
    707
    thanks senocular....cool

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center