/
staffNS.xml.js
221 lines (188 loc) · 9.75 KB
/
staffNS.xml.js
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
var sys = require("sys"),
dom = require(__dirname + "/../../../../lib/jsdom/level2/core").dom.level2.core;
exports.staffNS = function() {
var doc = new dom.Document("staff");
var implementation = new dom.DOMImplementation(doc, {
"XML" : ["1.0", "2.0"],
"core": ["1.0", "2.0", "3.0"]
});
var notations = new dom.NotationNodeMap(
doc,
doc.createNotationNode("notation1","notation1File", null),
doc.createNotationNode("notation2",null, "notation2File")
);
//<entElement domestic='Yes'>Element data</entElement><?PItarget PIdata?>
var entElement = doc.createElementNS("http://www.w3.org/2000/xmlns/","entElement");
entElement.setAttribute("domestic", "Yes");
entElement.appendChild(doc.createTextNode("Element data"));
var procElement = doc.createProcessingInstruction("PItarget", "PfIdata");
var ent4 = doc.createEntityNode("ent4",entElement, procElement);
var ent5 = doc.createEntityNode("ent5");
ent5.publicId = "entityURI";
ent5.systemId = "entityFile";
ent5.notationName = "notation1";
var entities = new dom.EntityNodeMap(
doc,
doc.createEntityNode("ent1", doc.createTextNode("es")),
doc.createEntityNode("ent2",doc.createTextNode("1900 Dallas Road")),
doc.createEntityNode("ent3",doc.createTextNode("Texas")),
ent4,
ent5
);
var defaultAttributes = new dom.NamedNodeMap(doc);
var entElement = doc.createElementNS("http://www.w3.org/2000/xmlns/","entElement");
entElement.setAttribute("attr1", "Attr");
entElement.setAttribute("domestic", "MALE");
defaultAttributes.setNamedItem(entElement);
var defaultAddress = doc.createElementNS("http://www.w3.org/2000/xmlns/","address");
defaultAddress.setAttribute("street", "Yes");
defaultAttributes.setNamedItem(defaultAddress);
doc.doctype = new dom.DocumentType(doc, "staff", entities, notations, defaultAttributes);
doc.doctype._systemId = "staffNS.dtd";
doc.implementation = implementation;
var staff = doc.createElementNS("http://www.w3.org/2000/xmlns/","staff");
var employee, address, name, position,gender,id, salary;
/************************************
* EMPLOYEEE 1 *
************************************/
employee = doc.createElementNS("http://www.w3.org/2000/xmlns/","employee");
address = doc.createElementNS("http://www.w3.org/2000/xmlns/","address");
name = doc.createElementNS("http://www.w3.org/2000/xmlns/","name");
position = doc.createElementNS("http://www.w3.org/2000/xmlns/","position");
gender = doc.createElementNS("http://www.w3.org/2000/xmlns/","gender");
id = doc.createElementNS("http://www.w3.org/2000/xmlns/","employeeId");
salary = doc.createElementNS("http://www.w3.org/2000/xmlns/","salary");
employee.appendChild(id);
employee.appendChild(name);
employee.appendChild(position);
employee.appendChild(salary);
employee.appendChild(gender);
employee.appendChild(address);
staff.appendChild(employee);
employee.namespaceURI = "http://www.nist.gov";
employee.setAttribute("xmlns", "http://www.nist.gov")
employee.setAttributeNS("http://www.nist.gov", "xmlns:dmstc", "http://www.usa.com");
id.appendChild(doc.createTextNode("EMP0001"));
salary.appendChild(doc.createTextNode("56,000"));
address.appendChild(doc.createTextNode('1230 North Ave. Dallas, Texas 98551'));
address.setAttributeNS("http://www.usa.com", "dmstc:domestic", "Yes");
name.appendChild(doc.createTextNode("Margaret Martin"));
gender.appendChild(doc.createTextNode("Female"));
position.appendChild(doc.createTextNode("Accountant"));
/************************************
* EMPLOYEEE 2 *
************************************/
employee = doc.createElementNS("http://www.w3.org/2000/xmlns/","employee");
address = doc.createElementNS("http://www.w3.org/2000/xmlns/","address");
name = doc.createElementNS("http://www.w3.org/2000/xmlns/","name");
position = doc.createElementNS("http://www.w3.org/2000/xmlns/","position");
gender = doc.createElementNS("http://www.w3.org/2000/xmlns/","gender");
id = doc.createElementNS("http://www.w3.org/2000/xmlns/","employeeId");
salary = doc.createElementNS("http://www.w3.org/2000/xmlns/","salary");
employee.appendChild(id);
employee.appendChild(name);
employee.appendChild(position);
employee.appendChild(salary);
employee.appendChild(gender);
employee.appendChild(address);
staff.appendChild(employee);
employee.setAttributeNS("http://www.nist.gov", "xmlns:dmstc", "http://www.usa.com");
id.appendChild(doc.createTextNode("EMP0002"));
salary.appendChild(doc.createTextNode("35,000"));
address.setAttributeNS("http://www.usa.com", "dmstc:domestic", "Yes");
address.setAttribute("street", "Yes");
address.appendChild(doc.createEntityReference("ent2"));
address.appendChild(doc.createTextNode(" Dallas, "));
address.appendChild(doc.createEntityReference("ent3"));
address.appendChild(doc.createTextNode("\n 98554"));
name.appendChild(doc.createTextNode("Martha Raynolds"));
name.appendChild(doc.createCDATASection("This is a CDATASection with EntityReference number 2 &ent2;"));
name.appendChild(doc.createTextNode("\r\n"));
name.appendChild(doc.createCDATASection("This is an adjacent CDATASection with a reference to a tab &tab;"));
gender.appendChild(doc.createTextNode("Female"));
position.appendChild(doc.createTextNode("Secretary"));
/************************************
* EMPLOYEEE 3 *
************************************/
employee = doc.createElementNS("http://www.nist.gov","employee");
address = doc.createElementNS("http://www.w3.org/2000/xmlns/","address");
name = doc.createElementNS("http://www.w3.org/2000/xmlns/","name");
position = doc.createElementNS("http://www.w3.org/2000/xmlns/","position");
gender = doc.createElementNS("http://www.w3.org/2000/xmlns/","gender");
id = doc.createElementNS("http://www.w3.org/2000/xmlns/","employeeId");
salary = doc.createElementNS("http://www.w3.org/2000/xmlns/","salary");
employee.appendChild(id);
employee.appendChild(name);
employee.appendChild(position);
employee.appendChild(salary);
employee.appendChild(gender);
employee.appendChild(address);
staff.appendChild(employee);
employee.setAttributeNS("http://www.nist.gov", "xmlns:dmstc", "http://www.netzero.com");
id.appendChild(doc.createTextNode("EMP0003"));
salary.appendChild(doc.createTextNode("100,000"));
address.setAttributeNS("http://www.usa.com", "dmstc:domestic", "Yes");
address.setAttribute("street", "No");
address.appendChild(doc.createTextNode("PO Box 27 Irving, texas 98553"));
name.appendChild(doc.createTextNode("Roger\n Jones")) ;
gender.appendChild(doc.createEntityReference("ent4"));
position.appendChild(doc.createTextNode("Department Manager"));
/************************************
* EMPLOYEEE 4 *
************************************/
employee = doc.createElementNS("http://www.nist.gov", "emp:employee");
address = doc.createElementNS("http://www.nist.gov", "emp:address");
name = doc.createElementNS("http://www.altavista.com", "nm:name");
position = doc.createElementNS("http://www.nist.gov", "emp:position");
gender = doc.createElementNS("http://www.nist.gov", "emp:gender");
id = doc.createElementNS("http://www.nist.gov", "emp:employeeId");
salary = doc.createElementNS("http://www.nist.gov", "emp:salary");
employee.appendChild(id);
employee.appendChild(name);
employee.appendChild(position);
employee.appendChild(salary);
employee.appendChild(gender);
employee.appendChild(address);
staff.appendChild(employee);
employee.setAttributeNS("http://www.nist.gov", "xmlns:emp", "http://www.nist.gov");
employee.setAttributeNS("http://www.altavista.com", "xmlns:nm", "http://www.altavista.com");
id.appendChild(doc.createTextNode("EMP0004"));
salary.appendChild(doc.createTextNode("95,000"));
address.setAttribute("emp:domestic", "Yes");
address.setAttribute("emp:street", "Y");
var ent1Ref = doc.createEntityReference("ent1");
//address.attributes.getNamedItem("street").childNodes.push(ent1Ref);
address.appendChild(doc.createTextNode("27 South Road. Dallas, Texas 98556"));
name.appendChild(doc.createTextNode("Jeny Oconnor"));
gender.appendChild(doc.createTextNode("Female"));
position.appendChild(doc.createTextNode("Personal Director"));
/************************************
* EMPLOYEEE 5 *
************************************/
employee = doc.createElementNS("http://www.w3.org/2000/xmlns/","employee");
address = doc.createElementNS("http://www.w3.org/2000/xmlns/","address");
name = doc.createElementNS("http://www.w3.org/2000/xmlns/","name");
position = doc.createElementNS("http://www.w3.org/2000/xmlns/","position");
gender = doc.createElementNS("http://www.w3.org/2000/xmlns/","gender");
id = doc.createElementNS("http://www.w3.org/2000/xmlns/","employeeId");
salary = doc.createElementNS("http://www.w3.org/2000/xmlns/","salary");
employee.appendChild(id);
employee.appendChild(name);
employee.appendChild(position);
employee.appendChild(salary);
employee.appendChild(gender);
employee.appendChild(address);
staff.appendChild(employee);
id.appendChild(doc.createTextNode("EMP0005"));
salary.appendChild(doc.createTextNode("90,000"));
address.setAttribute("street", "Yes");
address.appendChild(doc.createTextNode("1821 Nordic. Road, Irving Texas 98558"));
name.appendChild(doc.createTextNode("Robert Myers"));
gender.appendChild(doc.createTextNode("male"));
position.appendChild(doc.createTextNode("Computer Specialist"));
doc.appendChild(doc.createProcessingInstruction("TEST-STYLE", "PIDATA"));
doc.appendChild(doc.createComment(" This is comment number 1."));
doc.appendChild(staff);
doc.normalize();
return doc;
};