/// <summary> /// Serialize node /// </summary> /// <param name="node"></param> public void Serialize(VXmlNode node, short level) { Level = level; Type = node.NodeTypeCode; Name = node.Name; Value = node.Value; Content = null; VXmlContent ct = null; if (Type == DEFX.NODE_TYPE_CONTENT) { ct = (VXmlContent)node.GetNode(node.Id); Content = ct.ContentBytes; } VXmlAttributeCollection ac = node.Attributes; VXmlCommentCollection cc = node.CommentNodes; VXmlTextCollection tx = node.TextNodes; VXmlTagCollection tt = node.TagNodes; byte[] br = new byte[RESERVE_LENGTH]; // Reserve // Fixed part IO.Write(-1, level); // +08(2) - level IO.Write(-1, Type); // +10(2) - node type IO.Write(-1, (short)Name.Length); // +12(2) - name length IO.Write(-1, (long)Value.Length); // +14(8) - value length IO.Write(-1, (long)((Content == null) ? 0 : Content.Length)); // +22(8) - content length IO.Write(-1, (int)ac.Count); // +30(4) Number of attrs IO.Write(-1, (int)cc.Count); // +34(4) Number of comments IO.Write(-1, (int)tx.Count); // +34(4) number of text nodes IO.Write(-1, (int)tt.Count); // +38(4) number of tags IO.Write(-1, ref br); // +42(16)- reserve // Variable part IO.Write(-1, node.Name); // Name if (Value.Length > 0) { IO.Write(-1, Value); // Value } if (Content != null) { IO.Write(-1, ref Content); // Content } // Write attributes for (int i = 0; i < ac.Count; i++) { IO.Write(-1, (short)ac[i].Name.Length); // Attr name length IO.Write(-1, ac[i].Name); // Attr name IO.Write(-1, (int)ac[i].Value.Length); // Attr value length IO.Write(-1, ac[i].Value); // Attr value } // Write comments for (int i = 0; i < cc.Count; i++) { IO.Write(-1, (int)cc[i].Value.Length); // Comment value length IO.Write(-1, cc[i].Value); // Comment value } // Write text for (int i = 0; i < tx.Count; i++) { IO.Write(-1, (int)tx[i].Value.Length); // Text value length IO.Write(-1, tx[i].Value); // Text value } // Write tags for (int i = 0; i < tt.Count; i++) { IO.Write(-1, (int)tt[i].Value.Length); // Tag value length IO.Write(-1, tt[i].Value); // Tag value } }
/// <summary> /// Load child node from xml string /// </summary> /// <param name="xmlstring">XML string to load</param> /// <param name="name">Node name to create</param> /// <param name="fileref">Reference to file</param> /// <param name="parent">Parent VXML node</param> /// <returns></returns> private string load_xml_data(string xmlstring, string name, string xml_fileref, VXmlNode parent) { if (parent == null) { if (this.DocumentElement != null) { this.DocumentElement.Remove(); } } VXmlNode n = (parent == null) ? this : parent; if (!DEFX.BR_XML_IS_VALID_TYPE(n.NodeTypeCode)) { return(VXmlException.GetMessage(VXmlException.E0004_INVALID_NODE_TYPE_CODE) + ": " + n.NodeType); } VXMLTemplate t = null; if (template_cache == null) { template_cache = new List <VXMLTemplate>(32); } for (int i = 0; i < template_cache.Count; i++) { if (template_cache[i].template_name == name) { t = template_cache[i]; } } if (t == null) // Not found in cache { t = VXmlParser.Parse(xmlstring, name); if (t.Count == 1) { if (t[0].def == VXmlParser.DEF_ERROR) { return(VXmlException.GetMessage(VXmlException.E0020_XML_PARSE_ERROR_CODE) + ": " + t[0].value); // Return error } } } if (t.Count == 0) { return(""); } int j = 0; List <VXmlNode> stack = new List <VXmlNode>(); stack.Add(n); while (j < t.Count) { int stack_n = stack.Count - 1; if (t[j].def == VXmlParser.DEF_INSTRUCTION) { // Just ignore } else if (t[j].def == VXmlParser.DEF_COMMENT) { stack[stack_n].CreateComment(t[j].value); } else if (t[j].def == VXmlParser.DEF_ATTRIBUTE) { stack[stack_n].SetAttribute(t[j].name, t[j].value); } else if (t[j].def == VXmlParser.DEF_START) { if (t[j].type == DEFX.NODE_TYPE_TEXT) { stack[stack_n].CreateTextNode(t[j].value); } else { VXmlNode new_node = null; switch (t[j].type) { case DEFX.NODE_TYPE_CONTENT: new_node = stack[stack_n].CreateContent(""); break; case DEFX.NODE_TYPE_ELEMENT: new_node = stack[stack_n].CreateElement(t[j].name, t[j].value); break; default: break; } stack.Add(new_node); } } else if (t[j].def == VXmlParser.DEF_END) { if (stack[stack_n].NodeTypeCode == DEFX.NODE_TYPE_CONTENT) { VXmlContent c = ((VXmlContent)stack[stack_n]); if (c.fileref != "") { string xp = Path.GetDirectoryName(xml_fileref); string cp = Path.GetDirectoryName(c.fileref); if (cp == "") { cp = xp; // If path is not specified in the 'fileref' - use xml file path } string nm = Path.GetFileName(c.fileref); if (cp != "") { nm = cp + @"\" + nm; } if (File.Exists(nm)) { c.Upload(nm, true); c.fileref = nm; } else { return("Content file '" + nm + " is not found"); } } } if (t[j].type != DEFX.NODE_TYPE_TEXT) { stack.RemoveAt(stack_n); } } else { throw new VXmlException(VXmlException.E0020_XML_PARSE_ERROR_CODE, "- invalid parsed sequence: " + t[j].def); } j++; } return(""); }