


Detailed explanation of the solution when the & < > symbol exists when parsing xml strings
问题产生:
The entityname must immediately follow the '&' in the entity reference
经查发现 xml的内容里存在有 &符号 而 通过dom4j读取时 会发生错误
在xml中 “&”“”这样的标签存放在内容里是不合法的,会经常出问题。
下面找到解决方法:实测 替换 & 是可行的。
public void chartReplace(){ String str2 = "<logentry revision='1'>" + "<msg>In this comment, I fixed a <bug>, and <added> file1&&file2.</msg>" + "</logentry>"; System.out.println("original string: "+str2); //替换“&”:$1表示与(<msg>.*)的匹配子序列;$4表示与(.*</msg>)匹配的。 //&(?!amp;)表示匹配&而且后面不是amp;的字符串 //"$1&$3$4"得到的结果就是替换了<msg></msg>中的“&”为“&” //由于每次只能替换掉一个“&”,所以循环执行替换,直到替换后与替换前的字符串相等。 String str1 = ""; while(!str2.equals(str1)){ str1 = str2; str2 = str1.replaceAll("(<msg>.*)(&(?!amp;))(.*</msg>)", "$1&$3"); } System.out.println("firstly replace \"&\": "+str2); //替换“<” str1 = ""; while(!str2.equals(str1)){ str1 = str2; str2 = str1.replaceAll("(<msg>.*)(<)(.*</msg>)", "$1<$3"); } System.out.println("then replace \"<\": "+str2); //替换“<” str1 = ""; while(!str2.equals(str1)){ str1 = str2; str2 = str1.replaceAll("(<msg>.*)(>)(.*</msg>)", "$1>$3"); } System.out.println("finally replace \">\": "+str2); }
The above is the detailed content of Detailed explanation of the solution when the & < > symbol exists when parsing xml strings. For more information, please follow other related articles on the PHP Chinese website!

XMLisstillusedduetoitsstructurednature,humanreadability,andwidespreadadoptioninenterpriseenvironments.1)Itfacilitatesdataexchangeinsectorslikefinance(SWIFT)andhealthcare(HL7).2)Itshuman-readableformataidsinmanualdatainspectionandediting.3)XMLisusedin

The structure of an RSS document includes three main elements: 1.: root element, defining the RSS version; 2.: Containing channel information, such as title, link, and description; 3.: Representing specific content entries, including title, link, description, etc.

RSS documents are a simple subscription mechanism to publish content updates through XML files. 1. The RSS document structure consists of and elements and contains multiple elements. 2. Use RSS readers to subscribe to the channel and extract information by parsing XML. 3. Advanced usage includes filtering and sorting using the feedparser library. 4. Common errors include XML parsing and encoding issues. XML format and encoding need to be verified during debugging. 5. Performance optimization suggestions include cache RSS documents and asynchronous parsing.

RSS and XML are still important in the modern web. 1.RSS is used to publish and distribute content, and users can subscribe and get updates through the RSS reader. 2. XML is a markup language and supports data storage and exchange, and RSS files are based on XML.

RSS enables multimedia content embedding, conditional subscription, and performance and security optimization. 1) Embed multimedia content such as audio and video through tags. 2) Use XML namespace to implement conditional subscriptions, allowing subscribers to filter content based on specific conditions. 3) Optimize the performance and security of RSSFeed through CDATA section and XMLSchema to ensure stability and compliance with standards.

RSS is an XML-based format used to publish frequently updated data. As a web developer, understanding RSS can improve content aggregation and automation update capabilities. By learning RSS structure, parsing and generation methods, you will be able to handle RSSfeeds confidently and optimize your web development skills.

RSS chose XML instead of JSON because: 1) XML's structure and verification capabilities are better than JSON, which is suitable for the needs of RSS complex data structures; 2) XML was supported extensively at that time; 3) Early versions of RSS were based on XML and have become a standard.

RSS is an XML-based format used to subscribe and read frequently updated content. Its working principle includes two parts: generation and consumption, and using an RSS reader can efficiently obtain information.


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Chinese version
Chinese version, very easy to use

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver Mac version
Visual web development tools
