Advertisement
Advertisement
| 05.15.2008 at 11:34PM PDT, ID: 23407531 |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
|
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
| Microsoft |
| Apple |
| Internet |
| Gamers |
| Digital Living |
| Virus & Spyware |
| Hardware |
| Software |
| ITPro |
| Developer |
| Storage |
| OS |
| Database |
| Security |
| Programming |
| Web Development |
| Networking |
| Other |
| Community Support |
| 05.16.2008 at 12:20AM PDT, ID: 21580570 |
| 05.16.2008 at 06:17PM PDT, ID: 21587586 |
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: |
procedure ProcessNode(Node: TDOMNode; TreeNode: TTreeNode);
var
cNode: TDOMNode;
begin
if Node = nil then Exit; // Stops if reached a leaf
// Adds a node to the tree
// TEXT_NODE is a constant in the unit xmldom
if Node.nodetype = TEXT_NODE then
tree.Items.AddChild(TreeNode,Node.nodeValue)
else
begin
TreeNode := tree.Items.AddChild(TreeNode, Node.Attributes[0].NodeValue);
// Goes to the child node
cNode := Node.FirstChild;
// Processes all child nodes
while cNode <> nil do
begin
ProcessNode(cNode, TreeNode);
cNode := cNode.NextSibling;
end;
end;
end;
|
| 05.19.2008 at 10:07AM PDT, ID: 21599597 |
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: |
// Solution 1:
procedure Tree2XML(ADoc: TXMLDocument);
begin
// Assuming ADoc.Active = True and ADoc.DocumentElement exists
ProcessTreeNode(Tree.Items.GetFirstNode,ADoc.DocumentElement);
end;
procedure ProcessTreeNode(TreeNode: TTreeNode; XMLNode: IXMLNode);
var
NewNode: IXMLNode;
begin
if Assigned(TreeNode) and Assigned(XMLNode) then
begin
// Figure out what node to create.
// I believe the level property on a tree node is 0 based.
// You might want to double check.
case TreeNode.Level of
0: begin
NewNode := XMLNode.AddChild('companys');
NewNode.Attributes['name'] := TreeNode.Text;
ProcessTreeNode(TreeNode.getNext,NewNode);
end;
1: begin
NewNode := XMLNode.AddChild('task');
NewNode.Attributes['name'] := TreeNode.Text;
ProcessTreeNode(TreeNode.getNext,NewNode);
end;
else begin
with XMLNode.AddChild('timeassumption') do
begin
Attributes['name'] := TreeNode.Text;
NodeValue := TreeNode.getFirstChild.Text;
end;
with XMLNode.AddChild('packagedelivery') do
begin
Attributes['name'] := TreeNode.getNextSibling.Text;
NodeValue := TreeNode.getNextSibling.getFirstChild.Text;
end;
end;
end;
end;
end;
// Solution 2:
procedure Tree2XML(ADoc: TXMLDocument);
begin
// Assuming ADoc.Active = True and ADoc.DocumentElement exists
ProcessTreeNode(Tree.Items.GetFirstNode,ADoc.DocumentElement);
end;
procedure ProcessTreeNode(TreeNode: TTreeNode; XMLNode: IXMLNode);
var
NewNode: IXMLNode;
begin
if Assigned(TreeNode) and Assigned(XMLNode) then
begin
// If a tree node does not have any children then don't add the
// TreeNode.Text as an attribute, add it as a NodeValue.
if not TreeNode.hasChildren then
with XMLNode.AddChild('item') do
NodeValue := TreeNode.Text;
else
begin
NewNode := XMLNode.AddChild('item');
NewNode.Attributes['name'] := TreeNode.Text;
ProcessTreeNode(TreeNode.getFirstChild,NewNode);
end;
ProcessTreeNode(TreeNode.getNextSibling,XMLNode);
end;
end;
// If you use Solution 2 make this change to your XML2Tree ProcessNode
// procedure.
// Substitue this code for the line:
// TreeNode :=
// tree.Items.AddChild(TreeNode,Node.Attributes[0].NodeValue);
if Node.HasAttribute('name') then
tree.Items.AddChild(TreeNode,Node.Attributes[0].NodeValue)
else
tree.Items.AddChild(TreeNode,Node.NodeValue);
|
| 05.21.2008 at 10:54PM PDT, ID: 21621246 |