📄 xmlserialize.js
字号:
}; result = isc.StringBuffer.concat( result, (prefix != null ? isc.StringBuffer.concat("\r", prefix, "\t") : ""), isc.Comm._xmlSerialize((value != null ? value.$schemaId : null) || "elem", value, (prefix != null ? isc.StringBuffer.concat(prefix, "\t") : null), context) ); } // close xml tag result = isc.StringBuffer.concat( result, (prefix != null ? isc.StringBuffer.concat("\r", prefix) : ""), isc.Comm._xmlCloseTag(name) ); return result;},_isValidXMLIdentifier : function (name) { // XMLSerialize is used to transform arbitrary JS structures, including object literals // with strings for keys. XML accepts only a subset of characters that are valid in a // string. We encode them in an attribute value and have the server reconstitute them via // the special _isc_name encoding. But requests sent out of band of our server (direct // webservices for example) can't be helped in this manner. For those, we simply punt and // expect users to provide valid identifiers. // // It would be useful to report bad identifiers to the DeveloperConsole. Unfortunately, // the JS regexp character classes aren't powerful enough for us to do this without // recapitulating the unicode character ranges verbatim from the spec, which would be slow // and take up a lot of space. // // Note that our regexp matches a subset of the valid identifiers, but this is harmless // since our server reconstitues these. // // Spec is here: // http://www.w3.org/TR/REC-xml/#NT-Letter return isc.Comm.xmlSchemaMode || name.match(this._xmlIdentifierRegex);},//> @classMethod Comm._xmlSerializeObject() (A)// Internal routine to serialize an object.//// @group serialization// @param object (any) object to serialize// @param prefix (string) string to put before each line of serialization output// @param objRefs (object[]) array of objects that have been serialized already so// we don't get into endless loops // @param objPath (string) global variable path to this object, for serializing object references//// @return (string) serialized object as a string//<_xmlSerializeObject : function (name, object, objPath, objRefs, prefix, isRoot) { // open xml tag // // NOTE: we do need to explicitly label the structure we're about to write out as an "Object", // because for a single-property object like { values : { locale : 10 } } we'd currently write: // <container> // <values> // <someProperty>10</someProperty> // </values> // </container> // Without an explicit declaration that "values" is of Object type, this could be // interpreted as values being a subobject with a single property someProperty, or // <someProperty> being a *type name* which will be the value of the property "values". // Adding "Object" below causes us to write values as <values xsi:type="xsd:Object" .. >, // removing the ambiguity. var result = isc.Comm._xmlOpenTag(name, "Object", null, null, null, isRoot); var undef; // if it's a class or has the special _constructor property, then the name is the class name // this allows us to hand the output of this method to the server-side xml parser and get back // a DataSource-validated object back. if (isc.isAn.Instance(object)) name = object.getClassName(); else if (object._constructor) name = object._constructor; object = this._serialize_cleanNode(object); // for each key in the object for (var key in object) { if (key == null) continue; // XML identifiers can't start with $ (parser crashes) if (key.startsWith('$')) continue; var value = object[key]; // NOTE: null is a real value if (value === undef) continue; // if the value is a function, skip it // Exception - we can serialize actions by looking at function.iscAction - in this // case retain it if (isc.isA.Function(value) && !value.iscAction) continue; // convert the key to a string var keyStr = key.toString(); var context = { objRefs: objRefs, objPath: isc.Comm._serialize_addToPath(objPath, key), isRoot: false }; // transform the value result = isc.StringBuffer.concat( result, (prefix != null ? isc.StringBuffer.concat("\r", prefix, "\t") : ""), isc.Comm._xmlSerialize(keyStr, value, (prefix != null ? isc.StringBuffer.concat(prefix, "\t") : null), context) ); } // close xml tag result = isc.StringBuffer.concat( result, (prefix != null ? isc.StringBuffer.concat("\r", prefix) : ""), isc.Comm._xmlCloseTag(name) ); return result;},_getPrefix : function (prefixes, namespace) { if (prefixes[namespace] != null) { // re-use a declared prefix return prefixes[namespace]; } else { // establish a new NSURI -> prefix mapping if (prefixes._nsCount == null) prefixes._nsCount = 0; return (prefixes[namespace] = "ns" + prefixes._nsCount++); }}, // helper method - returns an xml open tag with the (optional) type._xmlOpenTag : function (tagName, type, namespace, prefix, leaveOpen, isRoot) { var output = isc.SB.create(); var writeNamespace = namespace != null; // if "prefix" is passed as an object, use it to accrue a map from namespace to namespace // prefix, but don't actually write out any namespaces, relying on the calling code to do // so if (namespace != null && isc.isAn.Object(prefix)) { writeNamespace = false; prefix = this._getPrefix(prefix, namespace); } // encode the name in '_isc_name' if it's not a valid XML identifier var extraXML = ''; if (!this._isValidXMLIdentifier(tagName)) { extraXML = ' _isc_name="' + tagName + '"'; tagName = "Object"; } if (namespace) { prefix = prefix || "schNS"; output.append("<", prefix, ":", tagName); if (writeNamespace) output.append(" xmlns:", prefix, "=\"", namespace, "\""); } else { output.append("<", tagName); } if (extraXML) output.append(extraXML); // if the object is root-level, we add the xsi namespace declaration to // allow usage of xsi types inline if (isRoot && !this.omitXSI) { output.append(" xmlns:xsi=\"http://www.w3.org/2000/10/XMLSchema-instance\""); } // if an xsi type is passed in for this object, mark the object with that type if (type && !this.omitXSI) { output.append(" xsi:type=\"xsd:", isc.makeXMLSafe(type), "\""); } if (!leaveOpen) output.append(">"); return output.toString();},// helper method - returns an xml close tag_xmlCloseTag : function (name, namespace, prefix) { if (namespace != null && isc.isAn.Object(prefix)) { prefix = this._getPrefix(prefix, namespace); } if (!this._isValidXMLIdentifier(name)) name = "Object"; if (namespace) { prefix = prefix || "schNS"; return isc.SB.concat("</", prefix, ":", name, ">"); } else { return isc.SB.concat("</", name, ">"); }},// helper method - returns the passed in value verbatim, sandwiched between the outputs of// _xmlOpenTag and _xmlClosetTag methods with the optional type._xmlValue : function (name, value, type, namespace, prefix) { if (type == "base64Binary") { value = "<xop:Include xmlns:xop=\"http://www.w3.org/2004/08/xop/include\" href=\"" + value + "\"/>"; } return isc.StringBuffer.concat( isc.Comm._xmlOpenTag(name, type, namespace, prefix), value, isc.Comm._xmlCloseTag(name, namespace, prefix) );}}); // END isc.addMethods(isc.Comm, {})
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -