الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

برنامج مفسر Xml و برنامج محول Xslt

بدأه رامي العيساوي في 16 أكتوبر 2009 · 2 رد · 1,188 مشاهدة · في JavaEE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكــم ورحمـة الله وبركاتــه ،،

هذا برنامج طلبته مني احدى الشركات الفنلندية بعد تقديمي على طلب للعمل لديهم فقد اختارو 32 شخص للمرحلة النهائية وطلبو منا هذا البرنامج

معلومات عن التطبيقين

XML CV - Java Application 

This project has two web pages:

1.( main.html ) : which will parse the XML file located on "http://ideakone.zxq.net/CV.xml" just for easy start up - a copy of that file is included in the source package- some features are clarified here

Complete separation between user interface and program logic, as you can notice that the main file is only a HTML file with out any Java or JSP codes. 
No need to relaod the page while parsing thanks to DWR technologies. 
The ability to add children nodes under the main categories and they will be manipulated automatically by the application. 
2.(usingXSLT.jsp) : which will parse the XML file located on "http://ideakone.zxq.net/CV.xml" using the XSL file located on "http://ideakone.zxq.net/CV.xsl" with XALAN help.



Note: this application was tested on Windows vista , Tomcat 6 , JDK 6 , IE8 , FF3.5 , Chrome 3.0.1

--------

Rami Alisawi

شيفرة الجافا

public class XmlFacilitator {

	public XmlFacilitator() {

	}

	public Document getDOC() {
		Document doc = null;
		try {
			DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
			DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
			doc = docBuilder.parse("http://ideakone.zxq.net/CV.xml");// create a Document object that represents the XML file.
			return doc;
		} catch (Exception ex) {
			ex.printStackTrace();
			return doc;
		}
	}

	public String processXSL() {
		StringWriter html = new StringWriter();
		try {
			TransformerFactory tF = TransformerFactory.newInstance();
			DOMSource xslDom = new DOMSource(getDOC()); // getting the Document object and initialize it as a source for the transforming process
			Transformer transformer = tF.newTransformer(new StreamSource("http://ideakone.zxq.net/CV.xsl"));
			transformer.transform(xslDom, new StreamResult(html));// the transforming process with XML Document and streaming the output as HTML to StringWriter
			return html.toString();

		} catch (Exception ex) {
			ex.printStackTrace();
			return ex.getMessage();

		}
	}
}

شيفرة برنامج مفسر XML

<body onload="dwr.util.useLoadingMessage();">
		<h1>XML CV Parser</h1>
		  <input type="button" onClick="main();" value="   Parse   ">

<script type="text/javascript">
function setupDiv(tag,value,place) // setting up the div before adding to the page
{
	var newDiv = dojo.doc.createElement("div");
	newDiv.innerHTML="<h5>"+tag+": "+value+"</h5>";
	dojo.style(newDiv, "opacity", "0"); // for fadeIn effect
	dojo.place(newDiv,place, "last"); // inserting the newDiv in the wanted div and to be the last div
	dojo.fadeIn({node:newDiv ,duration: 1000}).play();// for fadeIn effect
}
function main(){
	dwr.util.setValue("personalInformation",""); // clearing the Div
	dwr.util.setValue("Hobbies","");// clearing the Div
	Facilitator.getDOC(incoming); // calling the getDOC method from the class ws.ramy.xmlAssist.XmlFacilitator
	  function incoming(doc) { // dealing with the incoming Document object
	  var piElement=doc.getElementsByTagName("PersonalInformation")[0];
	  var hobbiesElement=doc.getElementsByTagName("Hobbies")[0];


		 console.log("+ Personal Information has "+piElement.childNodes.length +" Nodes"); // can be reomved
		 dojo.forEach(piElement.childNodes, function(input, i){
		 if(input.nodeName!="#text")setupDiv(input.nodeName,input.firstChild.nodeValue,"personalInformation");
		 console.log("...- "+input.nodeName+ " at index "+ i);// can be reomved
		 });


		 console.log("+ Hobbies have "+hobbiesElement.childNodes.length +" Nodes");// can be reomved
		 dojo.forEach(hobbiesElement.childNodes, function(input, i){
		 if(input.nodeValue==null){
			 console.log("...+ "+input.nodeName+ " has "+ input.childNodes.length +" Nodes at index ", i);// can be reomved
			 var name,description="";
			 dojo.forEach(input.childNodes, function(entry, j){
				 console.log(".........- "+entry.nodeName+ " at index "+ j);// can be reomved
				if(entry.nodeName!="#text") {
					if(entry.nodeName=="Name") name=entry.firstChild.nodeValue;
					else if(entry.nodeName=="Description") description=entry.firstChild.nodeValue;
				}

			 });
			  setupDiv(name,description,"Hobbies"); 
		 }
		 else console.log("...- ",input.nodeName+ " at index ", i);// can be reomved
		 });
	 }
}
		</script>
		<h2>Personal Information</h2>
		<div id="personalInformation"></div>
		<h2>Hobbies</h2>
		<div id="Hobbies"></div>
	</body>

معلومات تشغيل التطبيق داخل الملف المرفق

Instruction:
1-Upload the WAR file to any servelt/JSP container
2-Open the " /Ideakone " context with any well-known browser.
3-Make sure to allow the application to use Internet connection ,because XML and XSL files are on remote location

Source code:
Just change the extension of the file from ".war" to ".zip" then extract the files.

Files location:
/CV.xml
/CV.xsl
/main.html
/usingXSLT.jsp
/WEB-INF/classes/ws/ramy/xmlAssist/XmlFacilitator.java


-----------
Rami Alisawi

فما رايكم ساحصل العمل؟ :huh:

Application2.zip

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why

#2

إن شاء الله سوف تحصل عليه.

لقد فرحت جدا عندما رأيت عنوان موضوعك, أصل بقالي كذا يوم في عالم ال xslt و فرحت لما لقيتك بتآزرني

ليا سؤال, إنت ليه في مفسر ال xml مستخدمتش جافا DOM أو SAX مثلا, ليه javascript (او DWR على ما أظن)؟؟

#3

بالواقع انا استخدمت جافا DOM

يمكنك النظر في السورس كود

لتجد بانني مستورد المكتبات الخاصة بها

وهذا الكلاس ايضا يدل على انني استعملت الجافا DOM

DocumentBuilderFactory

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why

مواضيع مشابهة