axobj XMLDoc, "Msxml2.DOMDocument", 0, 0
XMLDoc("async") = 0
XMLDoc->"setProperty" "SelectionLanguage", "XPath"
sdim bufXML, 1024
bufXML = {"<persons>
<person>
<name>青木</name>
<age>24</age>
</person>
<person>
<name>川崎</name>
<age>18</age>
</person>
<person>
<name>坂本</name>
<age>32</age>
</person>
</persons>"}
XMLDoc->"loadXML" bufXML
root = XMLDoc("documentElement")
// person要素数の取得
comres nodelist
root->"getElementsByTagName" "person"
lenperson = nodelist("length")
// 挿入要素の作成
comres newperson
XMLDoc->"createElement" "person"
comres resTmp
newperson->"setAttribute" "type", "1"
comres newcomment
tmpbuf = "" + lenperson + "要素中2番目に挿入"
XMLDoc->"createComment" tmpbuf
newperson->"appendChild" newcomment
comres newname
XMLDoc->"createElement" "name"
newname("text") = "麻生"
newperson->"appendChild" newname
comres newage
XMLDoc->"createElement" "age"
newage("text") = "16"
newperson->"appendChild" newage
/*
// 川崎を含むperson要素の取得
comres findperson
root->"selectSingleNode" "/persons/person[name = '川崎']"
if( varuse(findperson) ){
root->"insertBefore" newperson, findperson
}
*/
//*
// 2番目に挿入
comres findperson
nodelist->"item" 1
root->"insertBefore" newperson, findperson
//*/
XMLDoc->"save" "persons.xml"
font msgothic, 12
mes XMLDoc("xml") |