PB如何解析XML?

zhaiyf 2006-11-08 11:54:52
PB如何解析XML?
有没有调用DOM的例子?
...全文
834 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
handi 2006-12-08
  • 打赏
  • 举报
回复
PBDOM Sybase不是已经出了么?
liyi830 2006-11-30
  • 打赏
  • 举报
回复
学习
青锋-SS 2006-11-29
  • 打赏
  • 举报
回复
试了都20天了,有结果了吗?
pieroshi 2006-11-29
  • 打赏
  • 举报
回复
Mark 关注
lovelihp 2006-11-29
  • 打赏
  • 举报
回复
mark。学习
zhaiyf 2006-11-08
  • 打赏
  • 举报
回复
然后呢?
node类型如何定义?有没有相关例子啊 ?
lzheng2001 2006-11-08
  • 打赏
  • 举报
回复
用connecttonewobject即可!
zhaiyf 2006-11-08
  • 打赏
  • 举报
回复
试一下,谢谢1+1!!!
lzheng2001 2006-11-08
  • 打赏
  • 举报
回复
主要就是用connecttonewobject 连接 MSXML2.DOMDocument.3.0 对象, 然后调用这个对象的属性方法。

结贴:)
lzheng2001 2006-11-08
  • 打赏
  • 举报
回复
老外的代码
lzheng2001 2006-11-08
  • 打赏
  • 举报
回复
pb9以下参考这个吧
oleobject lole_xml_document , lole_xsl_document //, lole_result
string ls_result
string ls_filename = "D:\testcases\pb8\PB_xml\Employees.XML"
string ls_xslfilename = "D:\testcases\pb8\PB_xml\pb_catalog_style.xsl"
// Create the OLE Object
lole_xml_document = CREATE oleobject
lole_xsl_document = CREATE oleobject
//lole_result = CREATE oleobject
// Connect to the parser
// NOTE : This example uses the parser from IE5.
// Use the class name "MSXML2.DOMDocument.3.0"
// Older version: Microsoft.XMLDOM
// for the latest version.

Integer li_rc

li_rc = lole_xml_document.ConnectToNewObject("MSXML2.DOMDocument.3.0")

IF li_rc < 0 THEN

MessageBox("Connecting to COM Object Failed", "Error: " + String(li_rc))

DESTROY lole_xml_document

Return

END IF


Integer li_rc1

li_rc = lole_xsl_document.ConnectToNewObject("MSXML2.DOMDocument.3.0")

IF li_rc1 < 0 THEN

MessageBox("Connecting to COM Object Failed", "Error: " + String(li_rc))

DESTROY lole_xsl_document

Return

END IF

// Load the file into memory (this will parse it)
boolean lb_test
lb_test=lole_xml_document.load(ls_filename)
IF lb_test = false THEN
//KK-Demonstrate the parseError attribute
MessageBox("Load of XML doc Failed", "ErrorCode: "+string(lole_xml_document.parseError.ErrorCode)+ "~n~r" &
+ "FilePosition: " +string(lole_xml_document.parseError.Filepos)+ "~n~r" &
+ "Line: " +string(lole_xml_document.parseError.Line)+ "~n~r" &
+ "LinePosition: " +string(lole_xml_document.parseError.Linepos)+ "~n~r" &
+ "Reason: " +string(lole_xml_document.parseError.Reason)+ "~n~r" &
+ "SourceText: " +string(lole_xml_document.parseError.SrcText))

DESTROY lole_xml_document

Return

END IF

// Load the file into memory (this will parse it)
boolean lb_test1
lb_test1=lole_xsl_document.load(ls_xslfilename)
IF lb_test1 = false THEN
//KK-Demonstrate the parseError attribute
MessageBox("Load of XML doc Failed", "ErrorCode: "+string(lole_xsl_document.parseError.ErrorCode)+ "~n~r" &
+ "FilePosition: " +string(lole_xsl_document.parseError.Filepos)+ "~n~r" &
+ "Line: " +string(lole_xsl_document.parseError.Line)+ "~n~r" &
+ "LinePosition: " +string(lole_xsl_document.parseError.Linepos)+ "~n~r" &
+ "Reason: " +string(lole_xsl_document.parseError.Reason)+ "~n~r" &
+ "SourceText: " +string(lole_xml_document.parseError.SrcText))

DESTROY lole_xsl_document

Return

END IF





//KK-Load the file name as the first treeviewitem
string ls_label //
ls_label = ls_filename
tv_xml.InsertItemLast (0, ls_label, 1)

// KK-root node element can be determined
// lole_xml_document.documentElement


// ********************************************
// THE XML FILE HAS BEEN PARSED AND IS IN MEMORY
// YOU CAN INVOKE PARSER METHODS TO MANIPULATE IT
// ********************************************
wf_parse_node(1,lole_xml_document.documentElement)


ls_result=lole_xml_document.transformNode(lole_xsl_document)
is_html_result=ls_result

mle_1.text=ls_result
// Disconnect from the XML parser
lole_xml_document.DisConnectObject()

lole_xsl_document.DisConnectObject()


// Destroy the OLE object
DESTROY lole_xml_document
DESTROY lole_xsl_document

public subroutine wf_parse_node (long al_treeview_parent, oleobject aole_node);// Arguments
//oleobject aole_node // The node to process
//long al_treeview_parent // The treeview item to add nodes to
//

// local variables
string ls_node_type // The type of the current node
string ls_node_name // The name of the current node
string ls_node_value // The value of the current node
oleobject lole_attribute_node_list // The attributes for this node
oleobject lole_attribute_node // An attribute for this node
oleobject lole_child_node_list // The child nodes for this node
oleobject lole_child_node // The current child node
long ll_max_attribute_nodes // The number of attribute nodes
long ll_max_child_nodes // The number of child nodes
long ll_attribute_idx // A counter
long ll_child_idx // A counter
string ls_label // The label for the treeview
long ll_treeview // The newly inserted treeview item
int li_pictureindex // KK-Added pictureindex


// Determine the node's name, type and value
ls_node_name = aole_node.nodename
ls_node_type = Upper(aole_node.nodetypestring)
ls_node_value = String(aole_node.nodevalue)


IF IsNull(ls_node_value) THEN
ls_node_value = "<NULL>"
END IF



// Add this node to the treeview
// I am using a picture index of 1 however
// you could use the nodetypestring to determine
// the node抯 type and use an appropriate picture
// KK-Added pictureindexes
choose case ls_node_type
case "ELEMENT"
li_pictureindex=2
case "ATTRIBUTE"
li_pictureindex=3
case "COMMENT"
li_pictureindex=4
case "TEXT"
li_pictureindex=5
end choose

ls_label = ls_node_name + " (" + ls_node_value + ")"
ll_treeview = tv_xml.InsertItemLast (al_treeview_parent, ls_label, li_pictureindex)



// If this node has attributes process them
lole_attribute_node_list = aole_node.attributes


IF IsValid(lole_attribute_node_list) THEN
ll_max_attribute_nodes = lole_attribute_node_list.length
ELSE
ll_max_attribute_nodes = 0
END IF


FOR ll_attribute_idx = 0 TO ll_max_attribute_nodes - 1
lole_attribute_node = lole_attribute_node_list.Item(ll_attribute_idx)
wf_parse_node (ll_treeview, lole_attribute_node) /* RECURSIVE */
NEXT



// If this node is an element and it has children process them
IF ls_node_type = "ELEMENT" THEN
lole_child_node_list = aole_node.childNodes


IF IsValid(lole_child_node_list) THEN
ll_max_child_nodes = lole_child_node_list.length
ELSE
ll_max_child_nodes = 0
END IF


FOR ll_child_idx = 0 TO ll_max_child_nodes - 1
lole_child_node = lole_child_node_list.Item(ll_child_idx)
wf_parse_node(ll_treeview, lole_child_node) /* RECURSIVE */
NEXT


END IF


zhaiyf 2006-11-08
  • 打赏
  • 举报
回复
可是啊可是,我用的是PB7.0,迷糊!!
lzheng2001 2006-11-08
  • 打赏
  • 举报
回复
pb9的话参考这个资料吧
http://blog.csdn.net/wu_07/archive/2005/12/12/550259.aspx

680

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder API 调用
社区管理员
  • API 调用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧