xmltree-view and unicode

Jo=?ISO-8859-1?B?6w==?=l Guillod joel.guillod at net2000.ch
Wed Apr 28 02:20:31 EDT 2004


Toma ,

Try the following script from my XML Utility Library. Any comments and
enhancements wellcome!

--
/******************************************************************
MedIPS Concept & Implementation

@author Joel Guillod
@copyright Joel Guillod
@version 1.0
@created 2003.08.29
@modified 2004.03.16
@url http://www.imed.ch/rev
@url mailto:medips at net2000.ch

***************************************************************** */

constant kAttributeNotFound = "XMLerr, can't find attribute"

/** 
@usage if xml.IsXMLErr(result()) then processError
@returns true when error occured with last XMLhandler (e.g.
revCreateXMLTreeFromFile, etc).
*/
function xml.IsXMLErr @rpResult
  if  item 1 of rpResult is "XMLerr" then return true
  else return false
end xml.IsXMLErr

/**
@usage put xml.tagForPath(aNode) into myTag
@sample put xml.tagForPath("/address/name[2]") into myTag -- => "name"
@returns the most bottom tag of the node path.
*/
function xml.tagForPath selectednode
  set the itemdel to "/"
  get last item of selectednode
  set the itemdel to "["
  return item 1 of it
end xml.tagForPath

/** get xml.textToUTF8(aString)
@purpose Converts a revolution string to a UTF8 string and returns it.
*/
function xml.textToUTF8 aString
  return unidecode(uniencode(aString),"UTF8")
end xml.textToUTF8

/** get xml.UTF8ToText(utf8String)
@purpose Converts a UTF8 string to a revolution string and returns it.
*/
function xml.UTF8ToText utf8String
  return unidecode(uniencode(utf8String,"UTF8"))
end xml.UTF8ToText

/** return xml.returnMsgAfterDeleteXmlTree(pXmlID,pMsg)
@sample if tActionNode is empty or xml.IsXMLErr(tActionNode) then return
xml.returnMsgAfterDeleteXmlTree(tXmlID,"next xml node not found:" &&
tActionNode)
*/
function xml.returnMsgAfterDeleteXmlTree pXmlID,pMsg
  revDeleteXMLTree pXmlID
  return pMsg
end xml.returnMsgAfterDeleteXmlTree

/** xml.utf8.setAttribute treeID,node,attributeName,aValue
@purpose Equivalent to: revSetXMLAttribute
treeID,node,attributeName,xml.textToUTF8(aValue)
@param aValue is a the text of a revolution field.
*/
on xml.utf8.setAttribute treeID,node,attributeName,aValue
  revSetXMLAttribute treeID,node,attributeName,xml.textToUTF8(aValue)
  return result()
end xml.utf8.setAttribute

/** get xml.utf8.Attribute(treeID,node,attributeName)
@purpose Equivalent to:
xml.UTF8ToText(revXMLAttribute(treeID,node,attributeName))
@returns is the standard text for revolution.
*/
function xml.utf8.attribute treeID,node,attributeName
  return xml.UTF8ToText(revXMLAttribute(treeID,node,attributeName))
end xml.utf8.attribute

/** xml.utf8.AddNode treeID,parentPath,nodeName,nodeContents
@purpose Equivalent to: revAddXMLNode
treeID,parentPath,nodeName,xml.textToUTF8(nodeContents)
@param nodeContents is a the text of a revolution field.
@returns Error description or node path.
*/
on xml.utf8.AddNode treeID,parentPath,nodeName,nodeContents
  revAddXMLNode treeID,parentPath,nodeName,xml.textToUTF8(nodeContents)
  return result()
end xml.utf8.AddNode

/** xml.utf8.SetNodeContents treeID,node,nodeContents
@purpose Equivalent to: evXMLPutIntoXMLNode
treeID,node,xml.textToUTF8(nodeContents)
@param nodeContents is a the text of a revolution field.
@returns Error description or node path.
*/
on xml.utf8.SetNodeContents treeID,node,nodeContents
  get xml.textToUTF8(nodeContents)
  revPutIntoXMLNode treeID,node,it
  return result()
end xml.utf8.SetNodeContents


/** get xml.utf8.NodeContents(treeID,node,attributeName)
@purpose Equivalent to: xml.UTF8ToText(revXMLNodeContents(treeID,node))
*/
function xml.utf8.NodeContents treeID,node
  return xml.UTF8ToText(revXMLNodeContents(treeID,node))
end xml.utf8.NodeContents


/**put xml.utf8.createTree(pRootTag) into tXmlTreeID
@purpose To create an xml tree with only the root tag.
@purpose Then can revAppendXML, revSetXMLAttribute, revSetXMLAttribute,
revXMLPutIntoXMLNode,Š to complete the tree.
*/
function xml.utf8.createTree pRootTag
  return revCreateXMLTree("<?xml version="&quote&"1.0"&quote&"
encoding="&quote&"utf-8"&quote&"?><" & \
      pRootTag & "></" & pRootTag & ">",false,true,false)
end xml.utf8.createTree


/**
@usage put xml.enclosedTextWithTag(aText,aTag) after myStream
@results is <aTag>aText</aTag>
*/
function xml.enclosedTextWithTag aText,aTag
  return merge("<[[aTag]]>[[aText]]</[[aTag]]>")
end xml.enclosedTextWithTag

/**
@usage xml.appendToStream aStream,aText
*/
on xml.appendToStream @aStream, at aText
  put aText after aStream
end xml.appendToStream
--



More information about the use-livecode mailing list