XMLNode.prototype.format - sending XML with CDATA to C#

Hi everyone I have been at this for quite sometime any help will be greatly appreciated.

I have a flash movie that loads an XML with CDATA in it.

This works great.

The user can edit the XML text in flash that it’s in an HTMLText field once done they can post it to a C# page. This is where my problem begins.

I’m using XMLNode.prototype.format = function(indent){ to add the CDATA tags to the edited HTML text, but it returns it as a string. and when I go to post the data i doesn’t post anything to the aspx. I can’t reload the string into a New XML because then it would remove the CDATA tags. Please help.


btn_save.onRelease = function(){
 
 var update_xml = new XML();
 update_xml.ignoreWhite = true;
 //update_xml.contentType = "text/xml";
 update_xml.xmlDecl = "<?xml version=\"1.0\"?>";
  
 slideid = "3";
 
 var entryNode = update_xml.createElement("entry"); 
 //entryNode.attributes.date = new Date().toString();
 
 //var slideidNode = update_xml.createElement("slideid"); 
 //var slideidText = update_xml.createTextNode(slideid); 
 
 var contentNode = update_xml.createElement("content"); 
// var contentText = update_xml.createTextNode(_root.form.htmlcontent.htmlText); 
 var contentText = update_xml.createTextNode("test"); 
 
 //_root.form.htmlcontent.htmlText
 //slideidNode.appendChild(slideidText); 
 contentNode.appendChild(contentText); 
 
 //entryNode.appendChild(slideidNode); 
 entryNode.appendChild(contentNode); 
 
 update_xml.appendChild(entryNode)
 
 contentNode.firstChild.isCDATA = true; 
    xmlstring = update_xml.format();
 
 //stringxml = "<entry><content><![CDATA[test]]></content></entry>"
 //trace("xml=" + xmlstring );
 //trace("isCDATA= "+update_xml.firstChild.isCDATA)
 //trace("htmltext="+_root.form.htmlcontent.htmlText)
 reply_xml = new XML();
 var reply_xml = new XML();
 reply_xml.ignoreWhite = true;
 // create XML instance for reply from Server page
 reply_xml.onLoad = onreply_xml;
 
 c = new LoadVars();
 //c.onLoad = function() { trace(this.s); };
 c.name = xmlstring;
 
 c.sendAndLoad("[http://localhost/emcor/xmlupdate.aspx](http://localhost/emcor/xmlupdate.aspx)", c, "POST");
 trace(c.name)
 //update_xml.load("[http://localhost/emcor/xmlupdate.aspx](http://localhost/emcor/xmlupdate.aspx)")
  //update_xml.load("xmlupdate.aspx")
 // update_xml.sendAndLoad("<A href="http://localhost/emcor/xmlupdate.aspx",reply_xml">http://localhost/emcor/xmlupdate.aspx",reply_xml, "POST");
 // new_update_xml.sendAndLoad("<A href="http://localhost/emcor/xmlupdate.aspx",reply_xml">http://localhost/emcor/xmlupdate.aspx",reply_xml);
   
 
 }
 
function onreply_xml () { 
 
 
 } 
 
XMLNode.prototype.format = function(indent){
 if (indent == undefined) indent = ""; 
 var str = ""; 
 var currNode = this.firstChild; 
 
 do{ 
 if (currNode.hasChildNodes()){ 
  //trace("has child = "+currNode);
  //trace(currNode.cloneNode(0).toString().slice(0,-2))
  str += indent + currNode.cloneNode(0).toString().slice(0,-2) + ">"; 
  str += currNode.format(indent+""); 
  str += indent + "</" + currNode.nodeName + ">"; 
 }else{
  //trace("no child = "+currNode);
  //trace("isdata = "+currNode.isCDATA)
  if (currNode.isCDATA) {
    str += indent + "<![CDATA[" + currNode.nodeValue + "]]>"; 
  }
  else {
   str += indent + currNode.toString() + ""; 
  }
 } 
 }while (currNode = currNode.nextSibling); 
 //trace(str);
 return str; 
} 


 =========================================
C# 
===========================================
 
[size=2][color=#0000ff]private[/color][/size][size=2] [/size][size=2][color=#0000ff]void[/color][/size][size=2] Page_Load([/size][size=2][color=#0000ff]object[/color][/size][size=2] sender, System.EventArgs e)

{

[/size][size=2][color=#008000]

[/color][/size][size=2]writeXML4();


}

[/size][size=2][color=#808080]///[/color][/size][size=2][color=#008000]*

[/color][/size][size=2][/size][size=2][color=#0000ff]public[/color][/size][size=2] [/size][size=2][color=#0000ff]static[/color][/size][size=2] [/size][size=2][color=#0000ff]void[/color][/size][size=2] FillArray([/size][size=2][color=#0000ff]ref[/color][/size][size=2] [/size][size=2][color=#0000ff]string[/color][/size][size=2][] arr) 

{

[/size][size=2][color=#008000]//string tempstring = "<entry><content><![CDATA[test]]></content></entry>";

[/color][/size][size=2][/size][size=2][color=#0000ff]string[/color][/size][size=2] xmlstr;

[/size][size=2][color=#008000]//string tempstring = arr[2];

[/color][/size][size=2][/size][size=2][color=#008000]//arr[2]= "";

[/color][/size][size=2][/size][size=2][color=#0000ff]if[/color][/size][size=2] (arr[2] != ""){

xmlstr = arr[2]; 



XmlDocument flashXML = [/size][size=2][color=#0000ff]new[/color][/size][size=2] XmlDocument();

flashXML.PreserveWhitespace = [/size][size=2][color=#0000ff]true[/color][/size][size=2];

flashXML.LoadXml (xmlstr);

XmlNode flashoNode = flashXML.DocumentElement;

XmlNodeList flashoNodeList = flashoNode.SelectNodes("/entry /content");

[/size][size=2][color=#008000]/*XmlNodeList IDflashoNodeList = flashoNode.SelectNodes("/entry/slideid");

for(int i = 0; i < IDflashoNodeList.Count; i++){

switch (IDflashoNodeList.Item(i).Name) 

{

case "slideid":

arr[0] = IDflashoNodeList.Item(i).InnerText;

break;

}

}*/[/color][/size][size=2] 

arr[0] = "3"; 

arr[1] = "test flash sent xml";

[/size][size=2][color=#0000ff]return[/color][/size][size=2];

[/size][size=2][color=#0000ff]for[/color][/size][size=2]([/size][size=2][color=#0000ff]int[/color][/size][size=2] i = 0; i < flashoNodeList.Count; i++)

{

[/size][size=2][color=#0000ff]switch[/color][/size][size=2] (flashoNodeList.Item(i).Name) {

[/size][size=2][color=#0000ff]case[/color][/size][size=2] "content":

arr[1] = flashoNodeList.Item(i).InnerText;

[/size][size=2][color=#0000ff]break[/color][/size][size=2];

}

}

} 

[/size][size=2][color=#0000ff]else[/color][/size][size=2] 

{

arr[0] = "3";

arr[1] = "nothing loaded";

}

}

[/size][size=2][color=#0000ff]void[/color][/size][size=2] writeXML4()

{

[/size][size=2][color=#0000ff]string[/color][/size][size=2] flashstring; 

[/size][size=2][color=#008000]//Response.ContentType = "text/xml";

[/color][/size][size=2]flashstring = HttpUtility.UrlDecode(Request.Form.ToString());

[/size][size=2][color=#008000]//string postData = this.Context.Request.Form.ToString();

[/color][/size][size=2][/size][size=2][color=#008000]//flashstring = System.Web.HttpUtility.UrlDecode(postData);

 

[/color][/size][size=2][/size][size=2][color=#0000ff]string[/color][/size][size=2][] myArray = {"parm 1","parm 2",flashstring}; 

[/size][size=2][color=#008000]// Pass the array using ref:

[/color][/size][size=2]FillArray([/size][size=2][color=#0000ff]ref[/color][/size][size=2] myArray);

[/size][size=2][color=#008000]//myArray[0] = "1";

[/color][/size][size=2][/size][size=2][color=#008000]//myArray[1] = flashstring;

[/color][/size][size=2]XmlDocument oXmlDoc = [/size][size=2][color=#0000ff]new[/color][/size][size=2] XmlDocument();

oXmlDoc.Load(Server.MapPath("menu.xml"));

XmlNode oNode = oXmlDoc.DocumentElement;

[/size][size=2][color=#008000]//Response.Write("<br>Node Name: " + oNode.Name + "<br>");

[/color][/size][size=2]XmlNodeList oNodeList = oNode.SelectNodes("/menus/button/subitem/body/content");

[/size][size=2][color=#008000]//Response.Write("<br>NodeList count=" + oNodeList.Count + "==test==" + oXmlDoc.Attributes + "<br>");

[/color][/size][size=2]

[/size][size=2][color=#0000ff]for[/color][/size][size=2]([/size][size=2][color=#0000ff]int[/color][/size][size=2] x = 0; x < oNodeList.Count; x++)

{ 

XmlNamedNodeMap mapAttributes = oNodeList.Item(x).Attributes;

[/size][size=2][color=#008000]//Add the attributes to the ListBox

[/color][/size][size=2][/size][size=2][color=#0000ff]foreach[/color][/size][size=2](XmlNode xnodAttribute [/size][size=2][color=#0000ff]in[/color][/size][size=2] mapAttributes)

{

[/size][size=2][color=#0000ff]switch[/color][/size][size=2] (xnodAttribute.Name) 

{

[/size][size=2][color=#0000ff]case[/color][/size][size=2] "slideid":

[/size][size=2][color=#0000ff]if[/color][/size][size=2] (xnodAttribute.Value == myArray[0]) {

XmlCDataSection CData;

CData = oXmlDoc.CreateCDataSection(myArray[1]); 

oNodeList.Item(x).InnerText = "";

oNodeList.Item(x).AppendChild(CData);

}

[/size][size=2][color=#0000ff]break[/color][/size][size=2];

}



[/size][size=2][color=#008000]//lbNodes.Items.Add(strIndent + " " + xnodAttribute.Name + " : " + xnodAttribute.Value);

[/color][/size][size=2][/size][size=2][color=#008000]//Response.Write( xnodAttribute.Name + " : " + xnodAttribute.Value + "<br>");

[/color][/size][size=2][/size][size=2][color=#008000]//xnodAttribute.Value = "sssss";

[/color][/size][size=2]} 



[/size][size=2][color=#008000]//Response.Write("<br>NodeList Item#" + x + " " + oNodeList.Item(x).InnerText + "<br>"); 

[/color][/size][size=2][/size][size=2][color=#008000]//Response.Write("<br>NodeList Item#" + x + " " + oNodeList.Item(x).ParentNode + "<br>"); 

[/color][/size][size=2]

}

 

oXmlDoc.Save(Server.MapPath("menu3.xml")); 



}

[/size]