XML解析以及增删改查的操作 2
我写了一个节点操作的接口INodeAction,直接贴代码: getPreviousSibling方法就是获取上一个相邻的节点,getNextSibling是获取下一个相邻的节点。 getBeifen方法主要是为了文档式化用。是根节点则返回0. printSpace方法就是根据节点辈分,在写文档的时候式化
我写了一个节点操作的接口INodeAction,直接贴代码:
getPreviousSibling方法就是获取上一个相邻的节点,getNextSibling是获取下一个相邻的节点。
getBeifen方法主要是为了文档格式化用。是根节点则返回0.
printSpace方法就是根据节点辈分,在写文档的时候格式化
再写了节点的基类Node:
import java.io.Serializable; import java.util.List; /** * xml文档节点基类,可以是普通节点,注释节点,文本节点 * */ public abstract class Node implements Serializable,INodeAction{ /** * 序列化版本号 */ private static final long serialVersionUID = 3858789701720999153L; /** * 父节点.规定 根节点的父节点为空 * */ protected Element father; /** * 由文档对象直接添加的节点 domFather赋值为document对象 * */ protected Document domFather; @Override public Integer getBeifen(){ Integer n; if(father==null){ n = 0; return n; } Node node = this; n = 0; while(node.father!=null){ n++; node = node.father; if(node.father==null){ return n; } } if(!(node.father==null)){ return null; } return n; } public Element getFather() { return father; } @Override public String printSpace() { StringBuffer sb = new StringBuffer(); Integer n = getBeifen(); if (n == null) { return sb.toString(); } for (int i = 0; i nodeList = domFather.getNodeList(); int idx = nodeList.indexOf(this); return idx==0?null:nodeList.get(idx-1); } } List<node> nodeList = father.getNodeList(); int idx = nodeList.indexOf(this); return idx==0?null:nodeList.get(idx-1); } @Override public Node getNextSibling() { if(father==null){ if(domFather==null){ DocumentUtil.throwException("节点还没添加到文档!"); }else{ List<node> nodeList = domFather.getNodeList(); int idx = nodeList.indexOf(this); return idx==nodeList.size()-1?null:nodeList.get(idx+1); } } List<node> nodeList = father.getNodeList(); int idx = nodeList.indexOf(this); return idx==nodeList.size()-1?null:nodeList.get(idx+1); } }</node></node></node>
关键在于编程的思想。有想法就什么都能实现。下面就是写节点的具体实现类了。另起一篇。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



With the popularity of smartphones, the screenshot function has become one of the essential skills for daily use of mobile phones. As one of Huawei's flagship mobile phones, Huawei Mate60Pro's screenshot function has naturally attracted much attention from users. Today, we will share the screenshot operation steps of Huawei Mate60Pro mobile phone, so that everyone can take screenshots more conveniently. First of all, Huawei Mate60Pro mobile phone provides a variety of screenshot methods, and you can choose the method that suits you according to your personal habits. The following is a detailed introduction to several commonly used interceptions:

[Analysis of the meaning and usage of midpoint in PHP] In PHP, midpoint (.) is a commonly used operator used to connect two strings or properties or methods of objects. In this article, we’ll take a deep dive into the meaning and usage of midpoints in PHP, illustrating them with concrete code examples. 1. Connect string midpoint operator. The most common usage in PHP is to connect two strings. By placing . between two strings, you can splice them together to form a new string. $string1=&qu

Analysis of new features of Win11: How to skip logging in to a Microsoft account. With the release of Windows 11, many users have found that it brings more convenience and new features. However, some users may not like having their system tied to a Microsoft account and wish to skip this step. This article will introduce some methods to help users skip logging in to a Microsoft account in Windows 11 and achieve a more private and autonomous experience. First, let’s understand why some users are reluctant to log in to their Microsoft account. On the one hand, some users worry that they

Introduction to PHP interface and how it is defined. PHP is an open source scripting language widely used in Web development. It is flexible, simple, and powerful. In PHP, an interface is a tool that defines common methods between multiple classes, achieving polymorphism and making code more flexible and reusable. This article will introduce the concept of PHP interfaces and how to define them, and provide specific code examples to demonstrate their usage. 1. PHP interface concept Interface plays an important role in object-oriented programming, defining the class application

PHP String Operation: A Practical Method to Effectively Remove Spaces In PHP development, you often encounter situations where you need to remove spaces from a string. Removing spaces can make the string cleaner and facilitate subsequent data processing and display. This article will introduce several effective and practical methods for removing spaces, and attach specific code examples. Method 1: Use the PHP built-in function trim(). The PHP built-in function trim() can remove spaces at both ends of the string (including spaces, tabs, newlines, etc.). It is very convenient and easy to use.

Ele.me is a software that brings together a variety of different delicacies. You can choose and place an order online. The merchant will make it immediately after receiving the order. Users can bind WeChat through the software. If you want to know the specific operation method , remember to check out the PHP Chinese website. Instructions on how to bind WeChat to Ele.me: 1. First open the Ele.me software. After entering the homepage, we click [My] in the lower right corner; 2. Then in the My page, we need to click [Account] in the upper left corner; 3. Then come to the personal information page where we can bind mobile phones, WeChat, Alipay, and Taobao. Here we click [WeChat]; 4. After the final click, select the WeChat account that needs to be bound in the WeChat authorization page and click Just [Allow];

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Table of Contents Astar Dapp Staking Principle Staking Revenue Dismantling of Potential Airdrop Projects: AlgemNeurolancheHealthreeAstar Degens DAOVeryLongSwap Staking Strategy & Operation "AstarDapp Staking" has been upgraded to the V3 version at the beginning of this year, and many adjustments have been made to the staking revenue rules. At present, the first staking cycle has ended, and the "voting" sub-cycle of the second staking cycle has just begun. To obtain the "extra reward" benefits, you need to grasp this critical stage (expected to last until June 26, with less than 5 days remaining). I will break down the Astar staking income in detail,
