extensionclient.java

来自「目前在JAVA下编程时对XML的操作很重要」· Java 代码 · 共 72 行

JAVA
72
字号
import org.apache.xmlbeans.*;
import com.localInfo.*;
import com.weather.*;
import java.io.File;

// Illustrates XMLBeans client application calling extended methods added to XMLBeans using Extension feature.

public class extensionClient {

	public static void main(String args[]) {

		try {

				if (args.length < 1 ) {

					System.out.println("Usage : java extensionClient <<InputFilePath>>");
					return;

				}

				String filePath = args[0];
				java.io.File inputXMLFile = new java.io.File(filePath);

	// Use XMLBeans built in class XmlObject to parse an XML document.

				XmlObject xmlObjExpected = XmlObject.Factory.parse(inputXMLFile);


	// Check document type of the object returned by the call to XmlObject.Factory.parse() method.
	// If type of object returned is of com.localInfo.LocalInfoDocumentXmlBean, then input xml document conforms to
	// localInfo.xsd .

				if (xmlObjExpected instanceof com.localInfo.LocalInfoDocumentXmlBean) {

					com.localInfo.LocalInfoDocumentXmlBean localInfoDoc = (com.localInfo.LocalInfoDocumentXmlBean)xmlObjExpected;
					LocalInfoDocumentXmlBean.LocalInfo localInfoObject = localInfoDoc.getLocalInfo();
					LocalWeatherDocumentXmlBean.LocalWeather localWeatherObject = localInfoObject.getLocalWeather();

	// Get temparature data in Celcius.

					float tempratureCelcius = localWeatherObject.getTemperatureInCelsius();

	// Get temparature data in Fahrenheit.

					float tempratureFahrenheit = localWeatherObject.getTemperature();

					System.out.println
					("Temprature of a location at zipcode " + localWeatherObject.getZipcode()  + " is: \n");

					System.out.print
					(tempratureFahrenheit  + " Fahrenheit or ");

					System.out.println
					(tempratureCelcius  + " Celcius. \n");


				} else {
					System.out.println("Input xml document doesn't" +
					"conform to localInfo.xsd");
				}


			} catch (Exception e) {


				e.printStackTrace();
			}

	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?