これを試して:
var elem = document.getElementsById('17');
var label = elem.getAttribute('label');
alert(label);
jQuery の使用:
alert($('#17').attr('label'));
次のような 300 個の要素があります。
次にこれを試してください:
$('rect').each(function(){
alert($(this).attr('label'));
});
ここにデモがあります
これを行う別の方法として、クラス属性をrect要素に追加し、そのクラスを使用してそれらを選択します。class="sample"
rect要素を追加しました。このフィドルをチェック
$('.sample').each(function(){
alert($(this).attr('label'));
});
サンプル xml ファイル。
<?xml version="1.0" encoding="utf-8" ?>
<Test>
<rect style="fill: #888888; display: inline;" id="17" width="35.823246" height="35.823246" x="456.61066" y="65.9505" class="seatObj" label="A18"></rect>
<rect style="fill: #888888; display: inline;" id="18" width="35.823246" height="35.823246" x="456.61066" y="65.9505" class="seatObj" label="A19"></rect>
</Test>
C# コンソール アプリケーションを使用した xml の解析:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
namespace Sample
{
class Program
{
static void Main(string[] args)
{
XmlDocument doc = new XmlDocument();
doc.Load("Url for Sample.xml");
XmlNodeList elemList = doc.GetElementsByTagName("rect");
for (int i = 0; i < elemList.Count; i++)
{
string attrVal = elemList[i].Attributes["label"].Value;
Console.WriteLine(attrVal);
}
Console.ReadLine();
}
}
}