- 浏览: 129494 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (165)
- 数据库 (45)
- 架构 (0)
- java web前端+框架 (9)
- java web后端+框架 (56)
- Eclipse插件 (1)
- 解题思路 (2)
- Eclipse (2)
- linux (6)
- jquery (4)
- 正则 (3)
- jsp (1)
- javascript (8)
- oracle (39)
- 生活 (1)
- weblogic (5)
- tomcat (3)
- Jrebel (1)
- powerdesigner (1)
- svn (1)
- log4j (1)
- IDE (1)
- POI (2)
- jvm (2)
- ssh (1)
- http (1)
- notepad++ (2)
- 润乾 (1)
- 设计模式 (0)
- 实用类Utils (2)
- 算法 (1)
- xml (1)
- 实用类 (2)
最新评论
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package samples.addr;
import org.w3c.dom.Attr;
import org.w3c.dom.CharacterData;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
* @author Matthew J. Duftler
* @author Sanjiva Weerawarana
*/
public class DOMUtils {
/**
* The namespaceURI represented by the prefix <code>xmlns</code>.
*/
private static String NS_URI_XMLNS = "http://www.w3.org/2000/xmlns/";
/**
* Returns the value of an attribute of an element. Returns null
* if the attribute is not found (whereas Element.getAttribute
* returns "" if an attrib is not found).
*
* @param el Element whose attrib is looked for
* @param attrName name of attribute to look for
* @return the attribute value
*/
static public String getAttribute (Element el, String attrName) {
String sRet = null;
Attr attr = el.getAttributeNode(attrName);
if (attr != null) {
sRet = attr.getValue();
}
return sRet;
}
/**
* Returns the value of an attribute of an element. Returns null
* if the attribute is not found (whereas Element.getAttributeNS
* returns "" if an attrib is not found).
*
* @param el Element whose attrib is looked for
* @param namespaceURI namespace URI of attribute to look for
* @param localPart local part of attribute to look for
* @return the attribute value
*/
static public String getAttributeNS (Element el,
String namespaceURI,
String localPart) {
String sRet = null;
Attr attr = el.getAttributeNodeNS (namespaceURI, localPart);
if (attr != null) {
sRet = attr.getValue ();
}
return sRet;
}
/**
* Concat all the text and cdata node children of this elem and return
* the resulting text.
*
* @param parentEl the element whose cdata/text node values are to
* be combined.
* @return the concatanated string.
*/
static public String getChildCharacterData (Element parentEl) {
if (parentEl == null) {
return null;
}
Node tempNode = parentEl.getFirstChild();
StringBuffer strBuf = new StringBuffer();
CharacterData charData;
while (tempNode != null) {
switch (tempNode.getNodeType()) {
case Node.TEXT_NODE :
case Node.CDATA_SECTION_NODE : charData = (CharacterData)tempNode;
strBuf.append(charData.getData());
break;
}
tempNode = tempNode.getNextSibling();
}
return strBuf.toString();
}
/**
* Return the first child element of the given element. Null if no
* children are found.
*
* @param elem Element whose child is to be returned
* @return the first child element.
*/
public static Element getFirstChildElement (Element elem) {
for (Node n = elem.getFirstChild (); n != null; n = n.getNextSibling ()) {
if (n.getNodeType () == Node.ELEMENT_NODE) {
return (Element) n;
}
}
return null;
}
/**
* Return the next sibling element of the given element. Null if no
* more sibling elements are found.
*
* @param elem Element whose sibling element is to be returned
* @return the next sibling element.
*/
public static Element getNextSiblingElement (Element elem) {
for (Node n = elem.getNextSibling (); n != null; n = n.getNextSibling ()) {
if (n.getNodeType () == Node.ELEMENT_NODE) {
return (Element) n;
}
}
return null;
}
/**
* Return the first child element of the given element which has the
* given attribute with the given value.
*
* @param elem the element whose children are to be searched
* @param attrName the attrib that must be present
* @param attrValue the desired value of the attribute
*
* @return the first matching child element.
*/
public static Element findChildElementWithAttribute (Element elem,
String attrName,
String attrValue) {
for (Node n = elem.getFirstChild (); n != null; n = n.getNextSibling ()) {
if (n.getNodeType () == Node.ELEMENT_NODE) {
if (attrValue.equals (DOMUtils.getAttribute ((Element) n, attrName))) {
return (Element) n;
}
}
}
return null;
}
/**
* Count number of children of a certain type of the given element.
*
* @param elem the element whose kids are to be counted
*
* @return the number of matching kids.
*/
public static int countKids (Element elem, short nodeType) {
int nkids = 0;
for (Node n = elem.getFirstChild (); n != null; n = n.getNextSibling ()) {
if (n.getNodeType () == nodeType) {
nkids++;
}
}
return nkids;
}
/**
* Given a prefix and a node, return the namespace URI that the prefix
* has been associated with. This method is useful in resolving the
* namespace URI of attribute values which are being interpreted as
* QNames. If prefix is null, this method will return the default
* namespace.
*
* @param context the starting node (looks up recursively from here)
* @param prefix the prefix to find an xmlns:prefix=uri for
*
* @return the namespace URI or null if not found
*/
public static String getNamespaceURIFromPrefix (Node context,
String prefix) {
short nodeType = context.getNodeType ();
Node tempNode = null;
switch (nodeType)
{
case Node.ATTRIBUTE_NODE :
{
tempNode = ((Attr) context).getOwnerElement ();
break;
}
case Node.ELEMENT_NODE :
{
tempNode = context;
break;
}
default :
{
tempNode = context.getParentNode ();
break;
}
}
while (tempNode != null && tempNode.getNodeType () == Node.ELEMENT_NODE)
{
Element tempEl = (Element) tempNode;
String namespaceURI = (prefix == null)
? getAttribute (tempEl, "xmlns")
: getAttributeNS (tempEl, NS_URI_XMLNS, prefix);
if (namespaceURI != null)
{
return namespaceURI;
}
else
{
tempNode = tempEl.getParentNode ();
}
}
return null;
}
public static Element getElementByID(Element el, String id)
{
if (el == null)
return null;
String thisId = el.getAttribute("id");
if (id.equals(thisId))
return el;
NodeList list = el.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
Node node = list.item(i);
if (node instanceof Element) {
Element ret = getElementByID((Element)node, id);
if (ret != null)
return ret;
}
}
return null;
}
}
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package samples.addr;
import org.w3c.dom.Attr;
import org.w3c.dom.CharacterData;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
* @author Matthew J. Duftler
* @author Sanjiva Weerawarana
*/
public class DOMUtils {
/**
* The namespaceURI represented by the prefix <code>xmlns</code>.
*/
private static String NS_URI_XMLNS = "http://www.w3.org/2000/xmlns/";
/**
* Returns the value of an attribute of an element. Returns null
* if the attribute is not found (whereas Element.getAttribute
* returns "" if an attrib is not found).
*
* @param el Element whose attrib is looked for
* @param attrName name of attribute to look for
* @return the attribute value
*/
static public String getAttribute (Element el, String attrName) {
String sRet = null;
Attr attr = el.getAttributeNode(attrName);
if (attr != null) {
sRet = attr.getValue();
}
return sRet;
}
/**
* Returns the value of an attribute of an element. Returns null
* if the attribute is not found (whereas Element.getAttributeNS
* returns "" if an attrib is not found).
*
* @param el Element whose attrib is looked for
* @param namespaceURI namespace URI of attribute to look for
* @param localPart local part of attribute to look for
* @return the attribute value
*/
static public String getAttributeNS (Element el,
String namespaceURI,
String localPart) {
String sRet = null;
Attr attr = el.getAttributeNodeNS (namespaceURI, localPart);
if (attr != null) {
sRet = attr.getValue ();
}
return sRet;
}
/**
* Concat all the text and cdata node children of this elem and return
* the resulting text.
*
* @param parentEl the element whose cdata/text node values are to
* be combined.
* @return the concatanated string.
*/
static public String getChildCharacterData (Element parentEl) {
if (parentEl == null) {
return null;
}
Node tempNode = parentEl.getFirstChild();
StringBuffer strBuf = new StringBuffer();
CharacterData charData;
while (tempNode != null) {
switch (tempNode.getNodeType()) {
case Node.TEXT_NODE :
case Node.CDATA_SECTION_NODE : charData = (CharacterData)tempNode;
strBuf.append(charData.getData());
break;
}
tempNode = tempNode.getNextSibling();
}
return strBuf.toString();
}
/**
* Return the first child element of the given element. Null if no
* children are found.
*
* @param elem Element whose child is to be returned
* @return the first child element.
*/
public static Element getFirstChildElement (Element elem) {
for (Node n = elem.getFirstChild (); n != null; n = n.getNextSibling ()) {
if (n.getNodeType () == Node.ELEMENT_NODE) {
return (Element) n;
}
}
return null;
}
/**
* Return the next sibling element of the given element. Null if no
* more sibling elements are found.
*
* @param elem Element whose sibling element is to be returned
* @return the next sibling element.
*/
public static Element getNextSiblingElement (Element elem) {
for (Node n = elem.getNextSibling (); n != null; n = n.getNextSibling ()) {
if (n.getNodeType () == Node.ELEMENT_NODE) {
return (Element) n;
}
}
return null;
}
/**
* Return the first child element of the given element which has the
* given attribute with the given value.
*
* @param elem the element whose children are to be searched
* @param attrName the attrib that must be present
* @param attrValue the desired value of the attribute
*
* @return the first matching child element.
*/
public static Element findChildElementWithAttribute (Element elem,
String attrName,
String attrValue) {
for (Node n = elem.getFirstChild (); n != null; n = n.getNextSibling ()) {
if (n.getNodeType () == Node.ELEMENT_NODE) {
if (attrValue.equals (DOMUtils.getAttribute ((Element) n, attrName))) {
return (Element) n;
}
}
}
return null;
}
/**
* Count number of children of a certain type of the given element.
*
* @param elem the element whose kids are to be counted
*
* @return the number of matching kids.
*/
public static int countKids (Element elem, short nodeType) {
int nkids = 0;
for (Node n = elem.getFirstChild (); n != null; n = n.getNextSibling ()) {
if (n.getNodeType () == nodeType) {
nkids++;
}
}
return nkids;
}
/**
* Given a prefix and a node, return the namespace URI that the prefix
* has been associated with. This method is useful in resolving the
* namespace URI of attribute values which are being interpreted as
* QNames. If prefix is null, this method will return the default
* namespace.
*
* @param context the starting node (looks up recursively from here)
* @param prefix the prefix to find an xmlns:prefix=uri for
*
* @return the namespace URI or null if not found
*/
public static String getNamespaceURIFromPrefix (Node context,
String prefix) {
short nodeType = context.getNodeType ();
Node tempNode = null;
switch (nodeType)
{
case Node.ATTRIBUTE_NODE :
{
tempNode = ((Attr) context).getOwnerElement ();
break;
}
case Node.ELEMENT_NODE :
{
tempNode = context;
break;
}
default :
{
tempNode = context.getParentNode ();
break;
}
}
while (tempNode != null && tempNode.getNodeType () == Node.ELEMENT_NODE)
{
Element tempEl = (Element) tempNode;
String namespaceURI = (prefix == null)
? getAttribute (tempEl, "xmlns")
: getAttributeNS (tempEl, NS_URI_XMLNS, prefix);
if (namespaceURI != null)
{
return namespaceURI;
}
else
{
tempNode = tempEl.getParentNode ();
}
}
return null;
}
public static Element getElementByID(Element el, String id)
{
if (el == null)
return null;
String thisId = el.getAttribute("id");
if (id.equals(thisId))
return el;
NodeList list = el.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
Node node = list.item(i);
if (node instanceof Element) {
Element ret = getElementByID((Element)node, id);
if (ret != null)
return ret;
}
}
return null;
}
}
发表评论
-
eclipse java代码格式化 javaformatter20150123.zip
2015-01-23 11:30 712eclipse java代码格式化 javaformatter ... -
List to Map
2015-01-21 17:22 482/** * <p>将List变为Map</p ... -
读取access工具类-ReadAccessUtil2
2015-01-06 13:52 550import com.healthmarketscience. ... -
ParameterizedType获取java泛型参数类型
2014-11-14 15:15 700ParameterizedType获取java泛型参数类型 ... -
分页帮助类-oracle-java
2014-10-09 17:46 459/** * 分页帮助类 * * @author ver ... -
java自动实例化List AutoArrayList
2014-07-21 15:51 739import java.util.ArrayList; p ... -
单一登录过滤器
2014-06-20 17:13 397/** * 单一登录过滤器 * * @author v ... -
正则 java 查找 打印 所有匹配项
2014-06-18 11:26 641package com.test.regex; import ... -
第3方包读取Access
2014-05-26 16:07 667package com.test; import java. ... -
多线程加签验签例子.zip
2014-05-26 16:08 512多线程加签验签例子.zip -
DateTimeUtils
2014-05-26 16:08 651import java.text.DateFormat; im ... -
listToMap
2014-05-26 16:09 437/** * List实用类 * * @author v ... -
JdbcTemplateRowMapper
2015-05-19 15:44 575import java.lang.reflect.Constr ... -
KeyValuePair2
2015-05-19 15:44 508/** * 键值对 * * @author verno ... -
OrderUtil -排序工具
2014-05-22 09:35 660/** * 排序工具 * * @author vern ... -
ZipUtils
2014-05-22 09:35 445import java.io.BufferedOutputSt ... -
TimerUtils
2014-05-22 09:34 479import org.slf4j.Logger; import ... -
Excel View 4 Spring
2014-05-22 09:29 339Excel View 4 Spring @RequestMa ... -
生成验证码 数学+字母
2014-04-01 10:08 440public static String getCharAnd ... -
ConnUtils2程序耗时输出 oracle.sql.Clob类型转换成String类型
2014-03-29 10:00 681package com.achievo.ems.web.ser ...
相关推荐
javacript 中获取和操作dom对象的工具方法
domutils 使用的DOM的实用程序。 所有功能均作为单个模块导出。 查看以查看可用的内容。生态系统姓名描述 快速而宽容HTML / XML解析器 htmlparser2的处理程序,可将文档转换为DOM 使用domhandler的DOM的实用程序CSS...
domUtils 从历史上看,通过JavaScript使用浏览器的文档对象模型(DOM)的工作比以前要困难得多,充满了许多不一致和浏览器错误,甚至使最优秀的开发人员都为之疯狂。 这些挑战是JavaScript帮助程序库(如jQuery)在...
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xsi:schemaLocation=...
domUtils ECMAScript 6 DOM实用程序 收集元素的框模型值(边距,边框,填充,宽度和高度)。 如果有必要, 将CSS属性名称转换为供应商特定的属性名称。 getElementSize 收集元素的框模型值(边距,边框,填充,...
domhandler, htmlparser2作为独立模块的dom domhandler DOM处理程序( 正式称为 DefaultHandler ) 创建一个包含页面所有节点的树。 树可以使用 DOMUtils 库操作。用法var handler = new DomHandler([ &l
具体到代码实现,首先通过Domutils.getDoc方法加载XML文件并创建Document对象。然后根据用户输入,决定调用相应的处理函数(addStudent、delStudent、updStudent)来对XML文件进行修改。 在添加学生信息的函数...
`DomUtils.java`文件可能是NekoHTML库中用于提供DOM操作的工具类。这个类可能包含了一系列静态方法,用于简化DOM节点的创建、查找、修改等任务。例如,它可能有方法用于获取特定标签的子节点、合并相邻的文本节点、...
Ueditor是由百度web前端研发部开发所见即所得的编辑器,具有轻量,可定制,注重用户体验等特点。...其中,核心层为开发者提供了诸如range、selection、domUtils类的底层API接口,中间的命令插件层不仅提供了大
Ueditor是由百度web前端研发部开发所见即所得的编辑器,具有轻量,可定制,注重用户体验等特点。...其中,核心层为开发者提供了诸如range、selection、domUtils类的底层API接口,中间的命令插件层不仅提供了大
Ueditor是由百度web前端研发部开发所见即所得的编辑器,具有轻量,可定制,注重用户体验等特点。...其中,核心层为开发者提供了诸如range、selection、domUtils类的底层API接口,中间的命令插件层不仅提供了大
每个属性收集了对应的方法内容flexible移动端rem适配方案RequestUtils基于axios请求的二次封装FeedbackUtilsjs反馈类的封装DomUtils该属性主要时针对dom元素相关的方法,针对于元素的一些操作DeviceUtils设备相关的...
例如,`js-utils`可能包含一个名为`domUtils`的模块,提供操作DOM节点的方法: ```javascript import { domUtils } from 'js-utils'; // 获取页面上的某个元素 const element = domUtils.getElementById('...
1. 核心层: 为命令层提供底层API,如range/selection/domUtils类。 2. 命令插件层: 基于核心层开发command命令,命令之间相互独立。 3. 界面层: 为命令层提供用户使用界面。 满足不同层次用户的需求。
1. 核心层: 为命令层提供底层API,如range/selection/domUtils类。 2. 命令插件层: 基于核心层开发command命令,命令之间相互独立。 3. 界面层: 为命令层提供用户使用界面。 满足不同层次用户的需求。 ...
1. 核心层: 为命令层提供底层API,如range/selection/domUtils类。 2. 命令插件层: 基于核心层开发command命令,命令之间相互独立。 3. 界面层: 为命令层提供用户使用界面。 满足不同层次用户的需求。
其中,核心层为开发者提供了诸如range、selection、domUtils类的底层API接口,中间的命令插件层不仅提供了大量的基础command,还允许开发者基于核心层进行command命令的开发,而面向用户端的界面层则可以提供自由...
其中,核心层为开发者提供了诸如range、selection、domUtils类的底层API接口,中间的命令插件层不仅提供了大量的基础command,还允许开发者基于核心层进行command命令的开发,而面向用户端的界面层则可以提供自由...
其中,核心层为开发者提供了诸如range、selection、domUtils类的底层API接口,中间的命令插件层不仅提供了大量的基础command,还允许开发者基于核心层进行command命令的开发,而面向用户端的界面层则可以提供自由...
其中,核心层为开发者提供了诸如range、selection、domUtils类的底层API接口,中间的命令插件层不仅提供了大量的基础command,还允许开发者基于核心层进行command命令的开发,而面向用户端的界面层则可以提供自由...