Xml
These two days are programmed for an RSS interface provided by another company, because they provide 1.0 version of RSS, where the XML part of the namespace, for this day and night for this, fell a lot of tumbling, Unicode coding problems, XPath problems, XSLT parsing problems. The following is a list of the solutions to these problems for the convenience of
The hypothetical xml file contains the following content ..
How to retrieve the internal or external content at a specific xml vertex... there is a simple example below... using xpath...
Part of asp.net (c #) Programs
Using System;Using System. Collections;Using System. Configuration;Using System. Data;Using System. Web;Using System. Web. Security;Using Syste
Today, with the help of the instance for configuring Oracle database connection, we will learn one way to read xml files (other reading methods will be introduced later): mdash; dom4j
Today, with the help of the instance for configuring Oracle database connection, we will learn one way to read xml files (other reading methods will be introduced later): mdash; dom4j
Today, with the help of the instance
XPath is the content of XML, where SelectNodes is a method of XmlDocument or XmlNode in C #. SelectNodes uses XPath to select nodes.Important syntaxSelectNodes ("item") Select the node named item from the son node of the current node. SelectNodes ("/item") Select the node named item from the son node of the root node. SelectNodes ("//item")Select the node named i
I have been asked many times why the DBA specification requires that the text () function be added to the XPath of the value method when parsing XML values, it seems that the result of adding and not adding is the same.
The following test script shows the difference between text () and why it is required.
Declare@ XML XML
Everyday Italian Giada De Laurentiis 2005 30.00 Harry Potter J K. Rowling 2005 29.99 XQuery Kick Start James McGovern Per Bothner Kurt Cagle James Linn Vaidyanathan Nagarajan 2003 49.99 Learning XML Erik T. Ray 2003 39.95
The above is the BookStore. xml file
Start processing
XDocument xdoc = XDocument.Load(); X
The code is as follows:
/*
*/
if (!function_exists (' l ')) {
function L () {
echo ' }
}
if (file_exists (' Test10_12.xml ')) {
$xml = simplexml_load_file (' Test10_12.xml ');
Finding node locations using the XPath method
$query = $xml->
The core idea of XPath design can be quickly introduced by xpath to locate the desired node. The main purpose is to describe the location of a node relative to another node. All qualified nodes can be obtained and become [location paths]. Xapth is mainly used to query information in XML documents. You can use path expressions to parse
Document directory
Processing node Nodes functions
Returns a Boolean function.
Function for processing string Strings
Function for processing numeric Numbers
Location path: path, which is equivalent to the path of a file in the file system. XML documents contain many elements and attributes. The Location of nodes, elements, and attributes specified according to the XPath syntax rules in the
Today, with the help of the instance for configuring Oracle database connection, we will learn one way to read xml files (other reading methods will be introduced later)-using dom4j + xpath.
Dom4j is an open-source XML parsing package produced by dom4j.org. Therefore, the package "dom4j-1.6.1.jar" must be copied to the web-inf/lib.
We take the
Copy codeThe Code is as follows:/**/If (! Function_exists ('l ')){Function l (){Echo '}}If (file_exists ('test10 _ 12. xml ')){$ Xml = simplexml_load_file ('test10 _ 12. xml ');// Use the xpath method to find the node location$ Query = $ xml->
Copy codeThe Code is as follows: /*
*/
If (! Function_exists ('l ')){
Function l (){
Echo '}
}
If (file_exists ('test10 _ 12. xml ')){
$ Xml = simplexml_load_file ('test10 _ 12. xml ');
// Use the xpath method to find the node location$ Query = $ xml->
Use an xpath expression to query the
28
23
22
Based on the requirements of the question, how can I write the xls document? Please kindly advise
------ Solution --------------------
$ S =
28
23
22
Book.xmlC # code://Determine if there is a value for the title: ' Harry Potter ' node existsStopwatch watch = Stopwatch.startnew ();var xmlDoc2 = new XmlDocument ();Xmldoc2.load (@ "Book.xml");var titleTextExpr4 = "/bookstore/book[title= ' Harry Potter ']/title";var titleTextNodes4 = xmldoc2.selectnodes (TITLETEXTEXPR4);Console.WriteLine ("XPath expression is/bookstore/book[title= ' Harry Potter ']/title, the number of nodes is:" + titletextnodes4.cou
Through XPath, we can quickly find the desired node, such:
Use the following code to search for the URL node xmlnodelist urlnodes = Doc. selectnodes ("/urlset/url ");
However, if you change the XML:
When xmlnodelist urlnodes = Doc. selectnodes ("/urlset/url") is used, an empty list is returned, that is, the URL node cannot be searched.
You can use xmlnamespacemanager to solve this problem:
XmlNamespac
) {
System.out.println ("
}
System.out.println ("-------------------");
Element product1 = Document.getrootelement (). Element ("Product");
The effect of Product1 is the same as the document query.
Pricelist = Product1.selectnodes (xmlPath1);
for (Element price:pricelist) {
System.out.println ("
}
System.out.println ("-------------------");
Element Price1 = (Element) Document.selectsinglenode (XMLPATH1);
if (price1!=null)
System.out.println ("
System.out.println ("-------------------");
Price1
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.