Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can get attributes of root element?

Tags:

jquery

xml

<?xml version="1.0" encoding="UTF-8"?>
<data columns="12" rows="0"/>

how can get attributes (rows) of root (data) element in jquery?

i can with

var records = $(xml).find(":first").parent().attr("rows");

but not works :-/

thanks Rob

like image 832
Roberto Avatar asked Jul 20 '10 15:07

Roberto


People also ask

Can XML root element have attributes?

The root element of an XML message is based on an object structure and an operation specified for the channel or service used for the communication. The root element can contain one or more attributes. The following table shows the attributes that can apply to root elements.

How many root elements are in XML?

While a properly formed XML file can only have a single root element, an XSD or DTD file can contain multiple roots. If one of the roots matches that in the XML source file, that root element is used, otherwise you need to select one to use. Choose the root to display. Select the root element you want to use.

What are root elements?

The <html> HTML element represents the root (top-level element) of an HTML document, so it is also referred to as the root element.

How do you define a root element in XML?

Each XML document has exactly one single root element. It encloses all the other elements and is, therefore, the sole parent element to all the other elements. ROOT elements are also called document elements. In HTML, the root element is the <html> element.


2 Answers

If it is a root node, use .filter() instead of .find().

var records = $(xml).filter(":first").attr("rows");
  • http://api.jquery.com/filter/

jQuery's .find() selects by searching inside the root nodes, while .filter() selects from among the root nodes.

like image 94
user113716 Avatar answered Oct 13 '22 22:10

user113716


Try

var records = $(xml).find("data").attr("rows");
like image 33
Ed. Avatar answered Oct 13 '22 22:10

Ed.