Parse XML sample code using jquery and jqueryxml sample code

Source: Internet
Author: User

Parse XML sample code using jquery and jqueryxml sample code

Xml file structure: books. xml

<? Xml version = "1.0" encoding = "UTF-8"?> <Root> <book id = "1"> <name> extjs </name> <author> JOHN </author> <price> 88 </price> </book> <book id = "2"> <name> sharp jQuery </name> <author> Li Si </author> <price> 99 </price> </book> <book id = "3"> <name> in-depth introduction to flex </name> <author> Wang Wu </author> <price> 108 </price> </book> <book id = "4"> <name> java Programming ideology </name> <author> Qian Qi </author> <price> 128 </price> </book> </root>

Page code:

<! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd"> 

:


How to Use jquery to add, delete, modify, and delete xml files

You can clearly describe the problem.

Is the XML data on the Web page operated?
Is it an operation on the passed XML data?
Is the XML file on the local hard disk operated?

Provide the following ideas:

You can use jquery's $. ajax () to request the xml resource. In this way, the parameter dataType: xml can be traversed on the local js Code. Display the file on the page. After modification and deletion, the data is transmitted to the background in JSON format for file read and write operations.
$. Ajax ({
Url: rootPath + "/userInfo. do? Method = saveSetting & columnIds =... ",
DataType: "json ",
Success: function (response ){
If (response ){

Alert ("saved successfully ");
}
Else
Alert ("failed to save ");
}
}
});

1. Read xml files/Content 1. Read xml files $. get (xmlfile. xml, function (xml) {// xml is the content that can be read and used. For details, see 2nd }); 2. Read xml content. If the read xml is used for the xml file, the above points are used to process the following $. get (xmlfile. xml, function (xml) {$ (xml ). fi
I. Reading xml files/Content
1. Read xml files
$. Get ("xmlfile. xml", function (xml ){
// Xml indicates the content that can be read and used. For details, refer to 2nd.
});
2. Read xml content
If the read xml is used for the xml file, the processing is as follows in combination with the above point:
$. Get ("xmlfile. xml", function (xml ){
$ (Xml). find ("item"). length;
});
If you read an xml string, note that the xml string must be surrounded by "<xml>" and "</xml>" before it can be parsed.
$ ("<Xml> <root> <item> </root> </xml> "). find ("item "). length; II. Example xml for parsing xml content: <? Xml version = "1.0" encoding = "UTF-8"?> <Fields>
<Field Name = "Name1">
<Fieldname> dsname </fieldname>
<Datatype> character </datatype>
</Field>
<Field Name = "Name2">
<Fieldname> dstype </fieldname>
<Datatype> character </datatype & ...... remaining full text>

JQUERY parses XML and returns html

Var xml = "the xml string"; var table = $ ("the table selector"); $ (xml ). find ("viewentry "). each (function () {var tr = $ ("<tr>"); $ (this ). find ("entrydata "). each (function () {tr. append ("<td>" + $ (this ). child ("text "). text + "</td>") ;}); table. append (tr) ;}); I have never tested it, but it is probably like this.


Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.