JAXP usage
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
public class Test {
public static void main(String[] args) {
String source = "<Customer_Products><result>0</result><resultMsg> </resultMsg></Customer_Products>";
InputStream is = null;
try {
is = new ByteArrayInputStream(source.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
Document document = null;
DocumentBuilder builder = null;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try {
builder = factory.newDocumentBuilder();
document = builder.parse(is);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(" resultMsg :"
+ document.getFirstChild().getChildNodes().item(1)
.getTextContent());
}
}
jaxp means java api for xml processing, it's obviously more convenient than dom4j, jdom etc..
The DOM parser is called a
DocumentBuilder
, as it builds an in-memory Document
representation. The javax.xml.parsers.DocumentBuilder
is created by the javax.xml.parsers.DocumentBuilderFactory
. The DocumentBuilder
creates an org.w3c.dom.Document
instance, which is a tree structure containing nodes in the XML Document. Each tree node in the structure implements the org.w3c.dom.Node
interface. There are many different types of tree nodes, representing the type of data found in an XML document. The most important node types are: from: http://en.wikipedia.org/wiki/Java_API_for_XML_Processing
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Is Eclipse IDE dying?In 2014 the Eclipse IDE is the leading development environment for Java with a market share of approximately 65%. but ac...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.