📄 prepostclient.java
字号:
import org.apache.xmlbeans.*;
import com.localInfo.*;
import com.weather.*;
import java.io.File;
// Illustrates XMLBeans client application modifying Map, and zipcode of a location.
public class prePostClient {
public static void main(String args[]) {
try {
if (args.length < 1 ) {
System.out.println("Usage : java prePostClient <<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();
ImageTypeXmlBean mapObject = localWeatherObject.getMapXmlBean();
// Get the size of old map
byte[] byteArray = mapObject.byteArrayValue();
int lengthOfOriginalMap = byteArray.length;
// Create an empty map, and then set it in localWeather object.
ImageTypeXmlBean newMapObject = localWeatherObject.addNewMapXmlBean();
localWeatherObject.setMapXmlBean(newMapObject);
// Get the size of new map
byte[] newByteArray = mapObject.byteArrayValue();
int lengthOfNewMap = newByteArray.length;
System.out.println
("Size of Original Map was " +lengthOfOriginalMap + " bytes.\nSize of new Map is " + lengthOfNewMap + " bytes.\n\n");
// Modify zipcode of localWeather object.
System.out.println(" Old Zipcode was : " + localWeatherObject.getZipcode() );
localWeatherObject.setZipcode("38920");
System.out.println(" New Zipcode is : " + localWeatherObject.getZipcode() );
} else {
System.out.println("Input xml document doesn't" +
"conform to localInfo.xsd");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -