[School] Homework DTC, Scheme, DOM in XML

Threads: An information management program and the student's books borrow description 1 save the TT following libraries: About SV include: Code SV, Full name, class and year of birth. Information of students borrow books include information about the book, day loan, pay day. Each book includes sv borrowed: Code book, title, Publisher, In XB. Each student can borrow various books.

1. XML Schema definition requirements:

  • Code SV, code consists of 4 including characters 2 the first character is the letter, 2 is the number of characters
  • Sv class is one of the values ​​cuat set of classes: CMPM1, CNPm2, CNPM3
  • Tong believes the book appear in order of code books, title, the XB, XB year

2. Drawing DOM model

3. Using both audiences XMLDOM browse the entire tree structure and display information secondary students 5 and information of the student loan pay

Award:

XML Schema Definition

<?xml version = "1.0"?>
<xs:schema xmlnx:xs = "www.w3.org/2001/XMLSchema">
	
	<!-- The goc thu vien gom cac phan tu QLMuon-->
	<xs:element name = "ThuVien">
		<xs:complexType>
			<xs:element name = "QLMuon" type = "KQLMuon"/>
		</xs:complexType>
	</xs:element>
	
	<!-- Thong tin gom Thong tin sinh vien va thong tin muon-->
	<xs:complexType name = "KQLMuon" minOccurs = "0">	
		<xs:element name = "SinhVien" type = "KSinhVien"/>
		<xs:element name = "Muon" type = "KMuon"/>
	</xs:complexType>
	
	<!-- Dinh nghia kieu sinh vien -->
	<xs:complexType name = "KSinhVien">
		<xs:sequense>
			<xs:element name = "MaSV" type = "KMa"/>
			<xs:element name = "Hoten" type = "xs:string"/>
			
			<!-- dinh nghia kieu lop-->
			<xs:element name = "Lop">
				<xs:simpleType>
					<xs:restriction base = "xs:string"/>
					<xs:pattern value = "CNPM1|CNPM2|CNPM3"/>
				</xs:simpleType>
			</xs:element>
			<!---ket thuc Lop-->
			
			<xs:element name = "NamSinh" type = "xs:date">
		</xs:sequense>
	</xs:complexType> 
	
	<!-- Dinh nghia kieu muon-->
	<xs:complexType name = "KMuon" minOccurs = "0">
		<xs:sequense>
			<xs:element name = "Sach" type = "KSach"/>
			<xs:element name = "NgayMuon" type = "xs:date"/>
			<xs:element name = "NgayTra" type = "xs:date"/>
		</xs:sequense>
	</xs:complexType>
	
	<!-- Dinh nghia kieu Sach-->
	<xs:complexType name = "KSach">
		<xs:sequense>
			<xs:element name = "MaSach" type = "KMa"/>
			<xs:element name = "TenSach" type = "xs:string"/>
			<xs:element name = "NXB" type = "xs:string"/>
			<xs:element name = "NamXB" type = "xs:Year"/>
		</xs:sequense>
	</xs:complexType>
	
	<!-- Dinh nghia Ma sach va Ma sinh vien-->
	<xs:simplexType name = "KMa">
		<xs:restriction base = "xs:string"/>
		<xs:pattern value = "[a-zA-Z]{2}[0-9]{2}">
	</xs:simplexType>
	
</xs:schema>

Chart DOM

In fact, you only need to turn on the internal structure of the tree is finished.

DOM model
DOM model

Browse and print out information on loan SV stuff 5

To browse and print out the information I need to use C #, Java, JavaScript, … Here, I use JavaScript.

<srcipt language = "JavaScript">
	function read(){
		var i, xmlDoc, QLMuonNode, ttSV, ttMuon, ttSach, output;
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.load("thuvien.xml");
		
		// lay thong tin sinh vien muon sach thu 5
		QLMuonNode = xmldoc.getElementsByTagName("QLMuon")[4];
		
		// lay toan bo cac node con cua SinhVien
		ttSV = QLMuonNode.firstChild.childNodes;
		
		for (i = 0; i < ttSV.length; i++){
			output += ttSV[i].nodeName + ":" + ttSV[i].nodeValue + <br/>
		}
		
		// lay toan bo cac node con cua Muon
		ttMuon = QLMuonNode.lastChild.childNodes;
		
		for (i = 1; i < ttMuon.length; i++){
			output += ttMuon[i].nodeName + ":" + ttMuon[i].nodeValue + <br/>
		}
		
		// lay toan bo cac node con cua Sach, Sach nam tai node[0] cua ttMuon
		ttSach = ttMuon[0].childNodes;
		
		for (i = 0; i < ttSach.length; i++){
			output += ttSach[i].nodeName + ":" + ttSach[i].nodeValue + <br/>
		}
		
		// hien thi thong tin
		document.write(output);
	}
</srcipt>