| Новости | FAQ | Авторы | Документация | В действии | Библиотека |
| Инструменты | Полезные ссылки | Хостинги | Скачать | Примеры | Форум |
dmx102 17.07.2006 12:49
# $Id: XmlParser.p,v 1.0.0.0 2006/07/06 Seomin Kirill Exp $
@CLASS
XmlParser
@create[]
#Ввод
@doXmlNew[docName;root]
$self.$docName[^xdoc::create[$root]]
@doXmlLoad[docName;fileName;flag]
^if(-f "$fileName"){
$self.$docName[^xdoc::load[$fileName]]
$result(true)
}{
$result(false)
}
^if($flag != 1){$result[]}
@getXmlRpc[docName;flag]
$self.$docName[^xdoc::create{$request:body}]
^if($self.$docName is xdoc){
$result(true)
}{
$result(false)
}
^if($flag != 1){$result[]}
#Узлы
@getNodeSelectFirst[docName;path;flag]
^if($self.$docName is xdoc){
$nodeList[^self.$docName.select[$path]]
^if($nodeList >= 1){
$result[$nodeList.0]
}
}{
$result(false)
}
^if($flag != 1){$result[]}
@doNodeAdd[docName;path;tag;value;flag]
^if($self.$docName is xdoc){
$node[^getNodeSelectFirst[$docName;$path]]
^if(($node is xnode) && ($node.nodeType == $xnode:ELEMENT_NODE)){
$nodeNew[^self.$docName.createElement[$tag]]
$temp[^node.appendChild[$nodeNew]]
$result(true)
^if(def $value){
$nodeNewValue[^self.$docName.createTextNode[$value]]
$nodeNew[^getNodeSelectFirst[$docName;$path/$tag]]
$temp[^nodeNew.appendChild[$nodeNewValue]]
}
}{
$result(false)
}
}{
$result(false)
}
^if($flag != 1){$result[]}
@doNodeDel[docName;path;flag]
^if($self.$docName is xdoc){
$node[^getNodeSelectFirst[$docName;$path]]
^if(($node is xnode) && ($node.nodeType == $xnode:ELEMENT_NODE)){
$nodeParent[$node.parentNode]
$temp[^nodeParent.removeChild[$node]]
$result(true)
}{
$result(false)
}
}{
$result(false)
}
^if($flag != 1){$result[]}
@setNodeValue[docName;path;value;flag]
^if($self.$docName is xdoc){
$node[^getNodeSelectFirst[$docName;$path]]
^if(($node is xnode) && ($node.nodeType == $xnode:ELEMENT_NODE)){
$node.firstChild.nodeValue[$value]
$result(true)
}{
$result(false)
}
}{
$result(false)
}
^if($flag != 1){$result[]}
@doNodeCopy[docNameFrom;pathFrom;docNameTo;pathTo;flag]
^if($self.$docName is xdoc){
$nodeFrom[^getNodeSelectFirst[$docNameFrom;$pathFrom]]
^if(($nodeFrom is xnode) && ($nodeFrom.nodeType == $xnode:ELEMENT_NODE)){
$nodeNew[^self.$docNameTo.importNode[$nodeFrom](-1)]
$nodeTo[^getNodeSelectFirst[$docNameTo;$pathTo]]
^if(($nodeTo is xnode) && ($nodeTo.nodeType == $xnode:ELEMENT_NODE)){
$temp[^nodeTo.appendChild[$nodeNew]]
$result(true)
}{
$result(false)
}
}{
$result(false)
}
}{
$result(false)
}
^if($flag != 1){$result[]}
@getNodeValue[docName;path;flag]
^if($self.$docName is xdoc){
$node[^self.getNodeSelectFirst[$docName;$path]]
^if(($node is xnode) && ($node.nodeType == $xnode:ELEMENT_NODE)){
$result[$node.firstChild.nodeValue]
}{
$result(false)
}
}{
$result(false)
}
^if($flag != 1){$result[]}
#Атрибуты
@doAttrAdd[docName;path;attr;value;flag]
^if($self.$docName is xdoc){
$node[^getNodeSelectFirst[$docName;$path]]
^if(($node is xnode) && ($node.nodeType == $xnode:ELEMENT_NODE)){
$attrNew[^self.$docName.createAttribute[$attr]]
$temp[^node.appendChild[$attrNew]]
$result(true)
^if(def $value){
$attrNewValue[^self.$docName.createTextNode[$value]]
$attrNew[^getNodeSelectFirst[$docName;$path/@$attr]]
$temp[^attrNew.appendChild[$attrNewValue]]
}
}{
$result(false)
}
}{
$result(false)
}
^if($flag != 1){$result[]}
@doAttrDel[docName;path;attr;flag]
^if($self.$docName is xdoc){
$node[^getNodeSelectFirst[$docName;$path]]
^if(($node is xnode) && ($node.nodeType == $xnode:ELEMENT_NODE)){
$temp[^node.removeAttribute[$attr]]
$result(true)
}{
$result(false)
}
}{
$result(false)
}
^if($flag != 1){$result[]}
@setAttrValue[docName;path;attr;value;flag]
^if($self.$docName is xdoc){
$node[^getNodeSelectFirst[$docName;$path]]
^if(($node is xnode) && ($node.nodeType == $xnode:ELEMENT_NODE)){
$temp[^node.setAttribute[$attr;$value]]
$result(true)
}{
$result(false)
}
}{
$result(false)
}
^if($flag != 1){$result[]}
@getAttrValue[docName;path;attr;flag]
^if($self.$docName is xdoc){
$node[^self.getNodeSelectFirst[$docName;$path]]
^if(($node is xnode) && ($node.nodeType == $xnode:ELEMENT_NODE)){
$result[^node.getAttribute[$attr]]
}{
$result(false)
}
}{
$result(false)
}
^if($flag != 1){$result[]}
#Вывод
@doXmlSave[docName;fileName;flag]
^if($self.$docName is xdoc){
^self.$docName.save[$fileName]
$result(true)
}{
$result(false)
}
^if($flag != 1){$result[]}
@getXmlXslt[docName;fileName;flag]
^if($self.$docName is xdoc){
^if(-f "$fileName"){
$xslt[^self.$docName.transform[$fileName]]
$result[^xslt.string[$.method[html]]]
}{
$result(false)
}
}{
$result(false)
}
^if($flag != 1){$result[]}
@getXmlPrint[docName;flag]
^if(def $self.$docName){
$result[^self.$docName.string[]]
}{
$result(false)
}
^if($flag != 1){$result[]}
@setXmlRpc[docName;flag]
^if($self.$docName is xdoc){
$response:body[^self.$docName.string[]]
}{
$result(false)
}
^if($flag != 1){$result[]}