Home Backend Development PHP Tutorial Modify the content of the specified XML tag c# Get the tag in the xml node c# xml null value tag Tencent qq xml message tag

Modify the content of the specified XML tag c# Get the tag in the xml node c# xml null value tag Tencent qq xml message tag

Jul 29, 2016 am 08:50 AM
xml Label

Modify the content of the specified tag in Xml (I am removing the spaces in the content of the specified tag)

In fact, it is a very simple method, friends who need it can take it directly.

test.xml

<span><?</span><span>xml version="1.0" encoding="UTF-8"</span><span>?></span><span><</span><span>DOCUMENT</span><span>></span><span><</span><span>item</span><span>></span><span><</span><span>key</span><span>></span>记录博客是一个很好的习惯<span></</span><span>key</span><span>></span><span><</span><span>url</span><span>></span>http://www.cnblogs.com/keerdi/p/5465549.html<span></</span><span>url</span><span>></span><span><</span><span>title</span><span>></span>去除XML的空格<span></</span><span>title</span><span>></span><span><</span><span>content</span><span>></span>养成一个好习惯很重要,  这是一段有空   格的文件内容,<span></</span><span>content</span><span>></span><span><</span><span>date</span><span>></span>2016-1-12<span></</span><span>date</span><span>></span><span></</span><span>item</span><span>></span><span><</span><span>item</span><span>></span><span><</span><span>key</span><span>></span>大家一起来写博客<span></</span><span>key</span><span>></span><span><</span><span>url</span><span>></span>http://www.cnblogs.com/keerdi/p/5465549.html<span></</span><span>url</span><span>></span><span><</span><span>title</span><span>></span>写博客可以增强记忆能力<span></</span><span>title</span><span>></span><span><</span><span>content</span><span>></span>一般安 装后的linux系统都是英文的界面,网上查  了一下各种说法  都有,  我只做了如下的配  置就好了,下载个中文包,改一下i18    n就完事了,并没有那么复杂<span></</span><span>content</span><span>></span><span><</span><span>date</span><span>></span>2016-1-12<span></</span><span>date</span><span>></span><span></</span><span>item</span><span>></span><span></</span><span>DOCUMENT</span><span>></span>
Copy after login

update.php

<?<span>php
    </span><span>function</span><span> actionGetXml(){
        </span><span>$xmlpath</span> = 'test.xml'<span>;
        </span><span>$xml</span> = <span>new</span> DOMDocument("1.0","UTF-8"<span>);
        </span><span>$xml</span>->load(<span>$xmlpath</span><span>);
        </span><span>$root</span> = <span>$xml</span>-><span>documentElement;
        </span><span>//</span><span> 获取标签总数</span><span>$nodes</span> = <span>$root</span>->getElementsByTagName("item"<span>);
        </span><span>for</span>(<span>$i</span>=0;<span>$i</span><=<span>$nodes</span>->length;<span>$i</span>++<span>){
            </span><span>//</span><span> 指定content标签,并获取content标签内容通过delTrim()方法去除所有空格</span><span>$str</span> = <span>$xml</span>->getElementsByTagName("content")->item(<span>$i</span><span>);
            </span><span>//</span><span> $str->nodeValue = "这里是要修改的内容";</span><span>$str</span>->nodeValue = <span>$this</span>->delTrim(<span>$str</span>-><span>nodeValue);
            </span><span>$xml</span>->save("test.xml"<span>);
        }
    }

    </span><span>//</span><span>删除空格</span><span>function</span> delTrim(<span>$object</span><span>) {
        </span><span>$search</span> = <span>array</span>(" ", " ", "\t", "\n", "\r"<span>);
        </span><span>$replace</span> = <span>array</span>("", "", "", "", ""<span>);
        </span><span>return</span><span>str_replace</span>(<span>$search</span>, <span>$replace</span>, <span>$object</span><span>);
    }
</span>?>
Copy after login

The above introduces the content of modifying XML specified tags, including xml and tag content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Can I open an XML file using PowerPoint? Can I open an XML file using PowerPoint? Feb 19, 2024 pm 09:06 PM

Can XML files be opened with PPT? XML, Extensible Markup Language (Extensible Markup Language), is a universal markup language that is widely used in data exchange and data storage. Compared with HTML, XML is more flexible and can define its own tags and data structures, making the storage and exchange of data more convenient and unified. PPT, or PowerPoint, is a software developed by Microsoft for creating presentations. It provides a comprehensive way of

Convert XML data to CSV format in Python Convert XML data to CSV format in Python Aug 11, 2023 pm 07:41 PM

Convert XML data in Python to CSV format XML (ExtensibleMarkupLanguage) is an extensible markup language commonly used for data storage and transmission. CSV (CommaSeparatedValues) is a comma-delimited text file format commonly used for data import and export. When processing data, sometimes it is necessary to convert XML data to CSV format for easy analysis and processing. Python is a powerful

Handling errors and exceptions in XML using Python Handling errors and exceptions in XML using Python Aug 08, 2023 pm 12:25 PM

Handling Errors and Exceptions in XML Using Python XML is a commonly used data format used to store and represent structured data. When we use Python to process XML, sometimes we may encounter some errors and exceptions. In this article, I will introduce how to use Python to handle errors and exceptions in XML, and provide some sample code for reference. Use try-except statement to catch XML parsing errors When we use Python to parse XML, sometimes we may encounter some

How to search for text across all tabs in Chrome and Edge How to search for text across all tabs in Chrome and Edge Feb 19, 2024 am 11:30 AM

This tutorial shows you how to find specific text or phrases on all open tabs in Chrome or Edge on Windows. Is there a way to do a text search on all open tabs in Chrome? Yes, you can use a free external web extension in Chrome to perform text searches on all open tabs without having to switch tabs manually. Some extensions like TabSearch and Ctrl-FPlus can help you achieve this easily. How to search text across all tabs in Google Chrome? Ctrl-FPlus is a free extension that makes it easy for users to search for a specific word, phrase or text across all tabs of their browser window. This expansion

Python parsing special characters and escape sequences in XML Python parsing special characters and escape sequences in XML Aug 08, 2023 pm 12:46 PM

Python parses special characters and escape sequences in XML XML (eXtensibleMarkupLanguage) is a commonly used data exchange format used to transfer and store data between different systems. When processing XML files, you often encounter situations that contain special characters and escape sequences, which may cause parsing errors or misinterpretation of the data. Therefore, when parsing XML files using Python, we need to understand how to handle these special characters and escape sequences. 1. Special characters and

How to handle XML and JSON data formats in C# development How to handle XML and JSON data formats in C# development Oct 09, 2023 pm 06:15 PM

How to handle XML and JSON data formats in C# development requires specific code examples. In modern software development, XML and JSON are two widely used data formats. XML (Extensible Markup Language) is a markup language used to store and transmit data, while JSON (JavaScript Object Notation) is a lightweight data exchange format. In C# development, we often need to process and operate XML and JSON data. This article will focus on how to use C# to process these two data formats, and attach

How to add tags on Douyin to attract traffic? Which tags on the platform are easiest to attract traffic to? How to add tags on Douyin to attract traffic? Which tags on the platform are easiest to attract traffic to? Mar 22, 2024 am 10:28 AM

As a popular short video social platform, Douyin has a huge user base. For Douyin creators, using tags to attract traffic is an effective way to increase the exposure of content and attract attention. So, how does Douyin use tags to attract traffic? This article will answer this question in detail for you and introduce related techniques. 1. How to add tags on Douyin to attract traffic? When posting a video, make sure to choose tags that are relevant to the content. These tags should cover the topic and keywords of your video to make it easier for users to find your video through tags. Leveraging popular hashtags is an effective way to increase your video’s exposure. Research current popular tags and trends and incorporate them into your video descriptions and tags. These popular tags usually have higher visibility and can attract the attention of more viewers. 3. Label

Using Python to implement data verification in XML Using Python to implement data verification in XML Aug 10, 2023 pm 01:37 PM

Using Python to implement data validation in XML Introduction: In real life, we often deal with a variety of data, among which XML (Extensible Markup Language) is a commonly used data format. XML has good readability and scalability, and is widely used in various fields, such as data exchange, configuration files, etc. When processing XML data, we often need to verify the data to ensure the integrity and correctness of the data. This article will introduce how to use Python to implement data verification in XML and give the corresponding

See all articles