The above two articles Article The first article explains the data structure required by sfdata, and the second article describes how to provide this data (data adapter) for sfdata. In this article, we will introduce the two data adapters sfdataxml and sfdataproject integrated by the system. Both data adapters are based on the XML format. Although sfdata does not care about whether the data comes from XML, it is difficult to find a better way to transmit data than XML, each XML data adapter must complete the following: 1. maps each element required by sfdata to a node in XML, and finds the node location of the object data in XML when requesting a specific object; 2. the attribute format required to convert the strings in the XML file to the object is based on these two points. We have two data adapters, sfdataxml and sfdataproject. These two data adapters are basically the same at the second point, that is to say, each entity (such as a task) reads and writes its attributes from XML in a similar way. The main difference between the two adapters lies in the differences in the document body structure, which are roughly as follows: 1. sfdataproject is mainly provided to directly support the XML format exported from Microsoft projects. sfdataxml is an improvement and improvement part based on this format. Mainly considering the performance of multipart loading and network applications; 2. in sfdataproject, tasks are all under the tasks node of the root document. The outlinenumber attribute is used to determine the tree-like subordination between each other. In sfdataxml, there is only one task node with the document, the Byte points of each node should be under its parent node, so that it is easy to implement multipart loading on demand; 3. taking into account the use of resource Gantt charts, the resources in sfdataxml are also arranged in the same tree structure as the aforementioned tasks. In sfdataproject, because Microsoft Project does not support resource Gantt charts, resources are only a list, this means that sfdataproject does not support resource Gantt Chart display. 4. sfdataxml supports two attributes: childrendataurl and nextsiblingdataurl for multipart loading. 5. sfdataproject does not actually support all the adapter interfaces, because it is too complex to cause confusion. It does not support the movetask and moveresource interfaces. This means that when a user has a mobile operation, the user can use the adapter. the document obtained by the getxml () method may not be in the correct format, but sfdataxml does not. Of course, in the multipart loading mode, getxml () of sfdataxml () the document returned by the method only contains the downloaded content. The above are the main differences between the two adapters, and these two adapters are in use, the text content in the XML node is resolved to the object property format specified by sfdata (for the list of attributes supported by sfdata, you can find it in the first article). Therefore, there is an object attribute list in the adapter (of course, these two lists are actually the same). Let's first look at this list:
| Entity type |
Attribute name |
XML node name |
Read/write Method |
| Task |
UID |
UID |
String |
| Task |
Summary |
Summary |
Bool2int |
| Task |
ID |
ID |
Int |
| Task |
Outlinenumber |
Outlinenumber |
String |
| Task |
Outlinelevel |
Outlinelevel |
Int |
| Task |
Start |
Start |
Time |
| Task |
Finish |
Finish |
Time |
| Task |
Name |
Name |
String |
| Task |
Readonly |
Readonly |
Bool2int |
| Task |
Percentcomplete |
Percentcomplete |
Int |
| Task |
Notes |
Notes |
String |
| Task |
Constrainttype |
Constrainttype |
Int |
| Task |
Constraintdate |
Constraintdate |
Time |
| Task |
Actualstart |
Actualstart |
Time |
| Task |
Actualfinish |
Actualfinish |
Time |
| Task |
Hyperlink |
Hyperlink |
String |
| Task |
Hyperlinkaddress |
Hyperlinkaddress |
String |
| Task |
Classname |
Classname |
String |
| Task |
Collapse |
Collapse |
Bool2int |
| Task |
Lineheight |
Lineheight |
Int |
| Task |
Critical |
Critical |
Bool2int |
| Task |
Baselinestart |
Baselinestart |
Time |
| Task |
Baselinefinish |
Baselinefinish |
Time |
| Resources |
UID |
UID |
String |
| Resources |
Summary |
Summary |
Bool2int |
| Resources |
Collapse |
Collapse |
Bool2int |
| Resources |
Name |
Name |
String |
| Resources |
ID |
ID |
Int |
| Resources |
Outlinenumber |
Outlinenumber |
String |
| Resources |
Outlinelevel |
Outlinelevel |
Int |
| Resources |
Readonly |
Readonly |
Bool2int |
| Resources |
Notes |
Notes |
String |
| Link |
UID |
UID |
String |
| Link |
Predecessoruid |
Predecessoruid |
String |
| Link |
Successoruid |
Successoruid |
String |
| Link |
Type |
Type |
Int |
| Resource allocation |
UID |
UID |
String |
| Resource allocation |
Taskuid |
Taskuid |
String |
| Resource allocation |
Resourceuid |
Resourceuid |
String |
| Resource Allocation | & Lt; TD width = "25%" & gt; units & lt;/TD & gt; & Lt; TD width = "25%" & gt; units & lt;/TD & gt;
float |
the following points can be found in the table above: 1. currently, all the attributes supported are the same as the XML node names and attribute names read by default. For example, a task has an attribute named start, the node name of the property content in the XML file is also called start; 2. currently, sfdataxml and sfdataproject support all the attributes of sfdata mentioned above, which means that in most cases, no new attributes need to be added for these two adapters. the read/write mode of each attribute must correspond to the specified type in sfdata. For example, the "Start" attribute is defined as a property of the "Date and Time" type in sfdata, the read/write type can only be "time". Of course, it is easy to add attribute support. You only need to call the addtaskproperty (proname, tagname, type), addresourceproperty (proname, tagname, type), addlinkproperty (proname, tagname, type), addassignmentproperty (proname, tagname, type) can be used to add new attributes for objects of a specific type. For example, we want to add support for the "Create Time" attribute of the task, which is of course a date and time type attribute. Let's assume that the node name in XML is "createdate ", we can add this property as follows: adapter. addtaskproperty ("createdate", "createdate", sfdatarender. getType ("time"); the first parameter above is the attribute name, and the second parameter is the node name of XML (in many cases, the two parameters are consistent, for example, in your xml file, "starttime" indicates the start time instead of the default "start".) The third parameter is the XML content read/write type, this parameter determines how the string in the XML file is converted into the attribute value when the object is read, and how to write the object attribute to the XML file when the object is updated, currently, the system supports the following five types of read/write:
| read/write type name |
description |
| int |
when reading XML, convert the content of the XML node to an integer using parseint (STR). When writing XML, you must also write an integer string |
| float |
when reading XML, the content of the XML node is converted to a floating point using parsefloat (STR). When writing XML, the floating point string is also ensured. |
& Lt; TD width = "50%" & gt; string & lt;/TD & gt;
| NO Conversion |
& Lt; TD width = "50%" & gt; Time & lt;/TD & gt;
| when reading XML, use sfglobal to read the content of the XML node. getdate (STR) is converted to a date object. When writing XML, the date attribute is converted to sfglobal. getdatestring (value, "S") is converted to XML in the format of 2009-05-03t14: 21: 09 |
| bool2int |
convert "1" to true when reading XML, and convert "0" to false when writing XML |
Although few read/write methods are supported, they can actually meet the needs. After all, in this conversion process, it is unlikely to implement too complex logic. However, if you need to customize the read/write class type, you can also define readfunc and writefunc. The readfunc (node) parameter is an XML node, you need to return the value read from the XML node. writefunc (node, value) has two parameters: XML node and attribute value. You need to write the attribute to the XML node. For example, assume that the following read/write method is implemented: the strings "true" and "false" are stored in the XML file. This attribute (such as collapse) is a Boolean value, we can use function readfunc (node) {If (sfajax. getnodevalue (node) = "true") {return true;} return false;} function writefu NC (node, value) {var STR = value? "True": "false"; sfajax. setnodevalue (node, STR);} rendertype = new sfdatarender (readfunc, writefunc) adapter. addtaskproperty ("collapse", "collapse", rendertype); in this way, the collapse attribute is changed to support saving with strings "true" and "false, instead of the "0" and "1" supported in the project. In this article, we briefly explain the implementation of sfdataxml and sfdataproject, mainly focusing on the property customization issues that users are concerned about. Here we need to add: both sfdataxml and sfdataproject support using the savechange parameter to specify whether to receive sfdata change notifications. If the savechange parameter is true, you can use the getxml () of the adapter at any time () returns the modified XML file. If it is false, the adapter will not save the user's changes because sfdataproject does not perfectly support saving user changes to files, therefore, the savechange parameter of sfdataproject is false by default, while that of sfdataxml is true.