losmejia
October 28th, 2004, 07:07 PM
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.h tmlText);
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", c, "POST");
trace(c.name)
//update_xml.load("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#
===========================================
private void Page_Load(object sender, System.EventArgs e)
{
writeXML4();
}
///*
public static void FillArray(ref string[] arr)
{
//string tempstring = "<entry><content><![CDATA[test]]></content></entry>";
string xmlstr;
//string tempstring = arr[2];
//arr[2]= "";
if (arr[2] != ""){
xmlstr = arr[2];
XmlDocument flashXML = new XmlDocument();
flashXML.PreserveWhitespace = true;
flashXML.LoadXml (xmlstr);
XmlNode flashoNode = flashXML.DocumentElement;
XmlNodeList flashoNodeList = flashoNode.SelectNodes("/entry /content");
/*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;
}
}*/
arr[0] = "3";
arr[1] = "test flash sent xml";
return;
for(int i = 0; i < flashoNodeList.Count; i++)
{
switch (flashoNodeList.Item(i).Name) {
case "content":
arr[1] = flashoNodeList.Item(i).InnerText;
break;
}
}
}
else
{
arr[0] = "3";
arr[1] = "nothing loaded";
}
}
void writeXML4()
{
string flashstring;
//Response.ContentType = "text/xml";
flashstring = HttpUtility.UrlDecode(Request.Form.ToString());
//string postData = this.Context.Request.Form.ToString();
//flashstring = System.Web.HttpUtility.UrlDecode(postData);
string[] myArray = {"parm 1","parm 2",flashstring};
// Pass the array using ref:
FillArray(ref myArray);
//myArray[0] = "1";
//myArray[1] = flashstring;
XmlDocument oXmlDoc = new XmlDocument();
oXmlDoc.Load(Server.MapPath("menu.xml"));
XmlNode oNode = oXmlDoc.DocumentElement;
//Response.Write("<br>Node Name: " + oNode.Name + "<br>");
XmlNodeList oNodeList = oNode.SelectNodes("/menus/button/subitem/body/content");
//Response.Write("<br>NodeList count=" + oNodeList.Count + "==test==" + oXmlDoc.Attributes + "<br>");
for(int x = 0; x < oNodeList.Count; x++)
{
XmlNamedNodeMap mapAttributes = oNodeList.Item(x).Attributes;
//Add the attributes to the ListBox
foreach(XmlNode xnodAttribute in mapAttributes)
{
switch (xnodAttribute.Name)
{
case "slideid":
if (xnodAttribute.Value == myArray[0]) {
XmlCDataSection CData;
CData = oXmlDoc.CreateCDataSection(myArray[1]);
oNodeList.Item(x).InnerText = "";
oNodeList.Item(x).AppendChild(CData);
}
break;
}
//lbNodes.Items.Add(strIndent + " " + xnodAttribute.Name + " : " + xnodAttribute.Value);
//Response.Write( xnodAttribute.Name + " : " + xnodAttribute.Value + "<br>");
//xnodAttribute.Value = "sssss";
}
//Response.Write("<br>NodeList Item#" + x + " " + oNodeList.Item(x).InnerText + "<br>");
//Response.Write("<br>NodeList Item#" + x + " " + oNodeList.Item(x).ParentNode + "<br>");
}
oXmlDoc.Save(Server.MapPath("menu3.xml"));
}
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.h tmlText);
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", c, "POST");
trace(c.name)
//update_xml.load("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#
===========================================
private void Page_Load(object sender, System.EventArgs e)
{
writeXML4();
}
///*
public static void FillArray(ref string[] arr)
{
//string tempstring = "<entry><content><![CDATA[test]]></content></entry>";
string xmlstr;
//string tempstring = arr[2];
//arr[2]= "";
if (arr[2] != ""){
xmlstr = arr[2];
XmlDocument flashXML = new XmlDocument();
flashXML.PreserveWhitespace = true;
flashXML.LoadXml (xmlstr);
XmlNode flashoNode = flashXML.DocumentElement;
XmlNodeList flashoNodeList = flashoNode.SelectNodes("/entry /content");
/*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;
}
}*/
arr[0] = "3";
arr[1] = "test flash sent xml";
return;
for(int i = 0; i < flashoNodeList.Count; i++)
{
switch (flashoNodeList.Item(i).Name) {
case "content":
arr[1] = flashoNodeList.Item(i).InnerText;
break;
}
}
}
else
{
arr[0] = "3";
arr[1] = "nothing loaded";
}
}
void writeXML4()
{
string flashstring;
//Response.ContentType = "text/xml";
flashstring = HttpUtility.UrlDecode(Request.Form.ToString());
//string postData = this.Context.Request.Form.ToString();
//flashstring = System.Web.HttpUtility.UrlDecode(postData);
string[] myArray = {"parm 1","parm 2",flashstring};
// Pass the array using ref:
FillArray(ref myArray);
//myArray[0] = "1";
//myArray[1] = flashstring;
XmlDocument oXmlDoc = new XmlDocument();
oXmlDoc.Load(Server.MapPath("menu.xml"));
XmlNode oNode = oXmlDoc.DocumentElement;
//Response.Write("<br>Node Name: " + oNode.Name + "<br>");
XmlNodeList oNodeList = oNode.SelectNodes("/menus/button/subitem/body/content");
//Response.Write("<br>NodeList count=" + oNodeList.Count + "==test==" + oXmlDoc.Attributes + "<br>");
for(int x = 0; x < oNodeList.Count; x++)
{
XmlNamedNodeMap mapAttributes = oNodeList.Item(x).Attributes;
//Add the attributes to the ListBox
foreach(XmlNode xnodAttribute in mapAttributes)
{
switch (xnodAttribute.Name)
{
case "slideid":
if (xnodAttribute.Value == myArray[0]) {
XmlCDataSection CData;
CData = oXmlDoc.CreateCDataSection(myArray[1]);
oNodeList.Item(x).InnerText = "";
oNodeList.Item(x).AppendChild(CData);
}
break;
}
//lbNodes.Items.Add(strIndent + " " + xnodAttribute.Name + " : " + xnodAttribute.Value);
//Response.Write( xnodAttribute.Name + " : " + xnodAttribute.Value + "<br>");
//xnodAttribute.Value = "sssss";
}
//Response.Write("<br>NodeList Item#" + x + " " + oNodeList.Item(x).InnerText + "<br>");
//Response.Write("<br>NodeList Item#" + x + " " + oNodeList.Item(x).ParentNode + "<br>");
}
oXmlDoc.Save(Server.MapPath("menu3.xml"));
}