domhelpertest.java
来自「在Struts2中的jar包xwork的源代码.版本为2.0.7」· Java 代码 · 共 62 行
JAVA
62 行
/* * Copyright (c) 2002-2003 by OpenSymphony * All rights reserved. */package com.opensymphony.xwork2.util;import java.io.StringReader;import junit.framework.TestCase;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.w3c.dom.NodeList;import org.xml.sax.InputSource;import com.opensymphony.xwork2.util.location.Location;/** * Test cases for {@link DomHelper}. */public class DomHelperTest extends TestCase { private String xml = "<!DOCTYPE foo [\n" + "<!ELEMENT foo (bar)>\n" + "<!ELEMENT bar (#PCDATA)>\n" + "]>\n" + "<foo>\n" + " <bar/>\n" + "</foo>\n"; public void testParse() throws Exception { InputSource in = new InputSource(new StringReader(xml)); in.setSystemId("foo://bar"); Document doc = DomHelper.parse(in); assertNotNull(doc); assertTrue("Wrong root node", "foo".equals(doc.getDocumentElement().getNodeName())); NodeList nl = doc.getElementsByTagName("bar"); assertTrue(nl.getLength() == 1); } public void testGetLocationObject() throws Exception { InputSource in = new InputSource(new StringReader(xml)); in.setSystemId("foo://bar"); Document doc = DomHelper.parse(in); NodeList nl = doc.getElementsByTagName("bar"); Location loc = DomHelper.getLocationObject((Element)nl.item(0)); assertNotNull(loc); assertTrue("Should be line 6, was "+loc.getLineNumber(), 6==loc.getLineNumber()); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?