📄 processxml.java
字号:
/*
* WebLogic Server Unleashed
*
*/
package com.wlsunleashed.xml.stream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import weblogic.xml.stream.Attribute;
import weblogic.xml.stream.AttributeIterator;
import weblogic.xml.stream.StartDocument;
import weblogic.xml.stream.StartElement;
import weblogic.xml.stream.XMLEvent;
import weblogic.xml.stream.XMLInputStream;
import weblogic.xml.stream.XMLInputStreamFactory;
import weblogic.xml.stream.XMLStreamException;
import weblogic.xml.stream.util.TypeFilter;
/**
* This class Processes a given XML using WebLogic Streaming API
* and dumps the contents on the screen
*
* @version 1.0
*/
public class ProcessXML {
/** The XML file to be processed */
private String fileName = null;
/**
* Creates a new StreamRepresentation object.
*
* @param file The XML file to be processed
*
*/
public ProcessXML(String file) {
fileName = file;
}
/**
* The entry point into this class - pass the XML file as
* parameter
*
* @param args Command line arguments
*/
public static void main(String[] args) {
if (args.length != 1) {
System.out.println("Usage: StreamRepresentation <XML file>.xml");
System.exit(1);
}
try {
ProcessXML xmlProcessor = new ProcessXML(args[0]);
xmlProcessor.process();
} catch (Exception ex) {
ex.printStackTrace();
}
}
/**
* Processes the given file
*
* @exceptions FileNotFoundException The file input was not found
* @exceptions XMLStreamException Problem while parsing.
*/
private void process()
throws FileNotFoundException, XMLStreamException {
XMLInputStreamFactory factory = XMLInputStreamFactory.newInstance();
TypeFilter aFilter = new TypeFilter(XMLEvent.START_DOCUMENT
| XMLEvent.START_ELEMENT);
XMLInputStream inputStream = factory.newInputStream(
new FileInputStream(fileName),
aFilter);
while (inputStream.hasNext()) {
XMLEvent anEvent = inputStream.next();
processEvent(anEvent);
}
}
/**
* Method processEvent.
*
* @param anEvent
*/
private void processEvent(XMLEvent anEvent) {
switch (anEvent.getType()) {
case XMLEvent.START_DOCUMENT:
StartDocument startDoc = (StartDocument) anEvent;
System.out.println(" In Start Doc: ");
System.out.println(" -- Name = " + startDoc.getName());
System.out.println(" -- System Id = " + startDoc.getSystemId());
break;
case XMLEvent.START_ELEMENT:
StartElement startElem = (StartElement) anEvent;
System.out.println(" In Start Element: ");
System.out.println(" -- name = " + startElem.getName());
AttributeIterator attrs = startElem.getAttributes();
while (attrs.hasNext()) {
Attribute anAttr = attrs.next();
System.out.println(" -- Attr name = " + anAttr.getName());
System.out.println(" -- -- Attr value = " + anAttr.getValue());
}
break;
default:
System.out.println(
"If you see this message, the filter has been changed");
break;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -