string ls_result
string ls_filename = "C:\nhdk.xml"
string ls_xslfilename = "C:\nhdk.xml"
// Create the OLE Object
lole_xml_document = CREATE oleobject
lole_xsl_document = CREATE oleobject
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
//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
ls_node_value = Space(100)
// 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
1 个解决方案
#1
贴XML……XML声明的编码和保存的编码是否匹配?
#1
贴XML……XML声明的编码和保存的编码是否匹配?