Working with XML in a browser using jquery

Source: Internet
Author: User
Tags object model reserved resource

XML is SGML on the web, but it's not as compelling on the web as the XML community. The most prominent achievements of XML on the Web--xhtml--have been entangled in political and commission design, and other ambitious, technically sound norms-such as XForms and svg---have been plagued by low usage rates. Sometimes XML succeeds on the Web in unexpected ways, including the popularity of XML-formatted web feeds (such as RSS types and Atom).

Common abbreviations

Ajax: Asynchronous JavaScript + XML

API: Application Programming Interface

CSS: Cascading Style Sheets

DOM: Document Object Model

HTML: Hypertext Markup Language

RSS: Really Simple aggregation

SGML: Standard Generic Markup Language

SVG: Scalable Vector Graphics

URI: Uniform Resource Identifier

URL: Uniform Resource Locator

World Wide Web Consortium: WWW Consortium

XHTML: Extensible Hypertext Markup Language

XML: Extensible Markup Language

Like other technologies on the Web, XML on the web is browser-centric, but most of the discussion about processing XML on the Web is focused on the server side. In the DeveloperWorks Firefox and XML series, I've introduced several ways to use XML in Firefox browsers. Unfortunately, cross-browser processing of XML is even more bizarre than cross-browser processing HTML, which is part of the reason why so many XML processing on the WEB adheres to a relatively secure server-side domain.

Many dynamic HTML developers are tired of the pain of Cross-browser and the quirks of scripting between browsers. The presence of several excellent JavaScript libraries makes the developer's job easier. One of the most popular of these libraries is that there are several articles on Jquery,developerworks that have been introduced. If you know how to circumvent these huge traps, you can also use JQuery to work with XML. In this article, I'll show you how to use jquery and XML together in a real-world scenario, how to use the Atom Web feed, introduce a practical model for working with XML in JQuery, and address the actual problems that are unfortunate. You need a basic understanding of XML, XML namespaces, HTML, JavaScript, and jQuery libraries.

Problems with XML namespaces

I will begin by introducing the most serious problems. JQuery does not completely solve the XML namespace problem. This well-known problem has a long history, people try various solutions, but the results are not satisfactory. The ideal solution might be to use JQuery to support the CSS Level 3 namespace selector, which will add a new selector as follows:

@namespace ex url(http://example.com);
ex|quote { font-weight: bold }

The first line is a prefix declaration for the Http://example.com namespace, and the second line is a type selector that uses the new namespace component, separating the declared prefix and local name with a vertical bar symbol. Unfortunately, JQuery does not support this approach, so people have taken various approaches to address namespace problems.

The importance of camouflage prefixes

One of the most common hacker methods is to ignore namespaces while processing XML and namespaces in JQuery and select the full QName (prefix and local part).

$(xml).find("x\\:quote").each(function() {
   //process each node
  });

The code is selected through JQuery's node name concept, the DOM nodename attribute. It contains a colon, a symbol reserved by the JQuery selector, and must be escaped using a backslash. A backslash is a reserved symbol for a JavaScript script and must be a pair. This hacker method cannot be used in a namespace-equivalent document using a different prefix.

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.