用jquery解析xml文件
测试用的xml文件
<?xml version="1.0" encoding="UTF-8"?>
<schools>
<school id='111'>测试学校</school>
<school id='222'>测试学校22
<class id='2.1'>测试班级222</class>
</school>
</schools>
测试用的JavaScript代码
$().ready(function(){
$.post("/index_school/test_data.xml",function(data){
//解析xml文件中的信息
$(data).find('school').each(function(){
var $school = $(this);
//获取属性
var schoolId = $school.attr("id");
//获取标签中的文本
var schoolText = $school.text();
//获取子元素的属性和文本
/*
$school.find('class').each(function(){
var $schoolClass = $(this);
alert( $schoolClass.attr("id") + "--" +$schoolClass.text() );
})*/
//如果没有,则在使用之前要进行判断
var classId = $school.children('class').attr("id");
if(classId!=null){
alert(classId);
}
})
});
});
相关文档:
VC解析XML--使用CMarkup类解析XML
(一) 先讲一下XML中的物殊字符,手动填写时注意一下。
字符 字符实体
& &nb ......
先创建数据然后生成相应的xml文件
DataSet ds = new DataSet();
#region Parent Table
DataTable dt1 = new DataTable("Parent");
......
<
<
小于
>
>
大于
&
&
和号
'
'
单引号
"
"
引号
注释:在 XML 中,只有字符 "<" 和 "&" 确实是非法的。大于号是合法的,但是用实体引用来代替它是一个好习惯。 ......
转:http://hi.baidu.com/oneshotonekill/blog/item/be68b513f7c929d7f6039e1e.html
Whitespace is not allowed before an XML Processing Instruction (< ? ... ?>). HTMLComponent.Eclipse在编辑mxml的时候提示这样的错误。检查才发现代码中在<? ?>之前存在空格。 ......
DECLARE @x xml
SET @x='
<root>
<ShopAccount>
<ActivityType>IA - PM Standing WO (for LPI report)</ActivityType>
<ProjectNo>R</ProjectNo>
</ShopAccount>
<ShopAccount>
......