PowerBuilder XML Document Parse Using PBDOM OR OleObject
Source Code w_main from window
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 |
forward global type w_main from window end type type cb_9 from commandbutton within w_main end type type cb_8 from commandbutton within w_main end type type cb_7 from commandbutton within w_main end type type cb_6 from commandbutton within w_main end type type cb_5 from commandbutton within w_main end type type cb_4 from commandbutton within w_main end type type tv_1 from treeview within w_main end type type cb_3 from commandbutton within w_main end type type cb_2 from commandbutton within w_main end type type mle_1 from multilineedit within w_main end type type cb_1 from commandbutton within w_main end type end forward global type w_main from window integer width = 3534 integer height = 1900 boolean titlebar = true string title = " XML Document" boolean controlmenu = true boolean minbox = true boolean maxbox = true boolean resizable = true long backcolor = 67108864 string icon = "AppIcon!" boolean center = true cb_9 cb_9 cb_8 cb_8 cb_7 cb_7 cb_6 cb_6 cb_5 cb_5 cb_4 cb_4 tv_1 tv_1 cb_3 cb_3 cb_2 cb_2 mle_1 mle_1 cb_1 cb_1 end type global w_main w_main forward prototypes public subroutine wf_buildtree (pbdom_object apbdom_obj[], long al_parent) public function long wf_createtv (pbdom_object a_obj_node, boolean isfirst, long parenthandle, long handle) public function boolean of_findelementwithattributevalue (pbdom_element apbdom_found, string as_element, string as_attribute, string as_value, pbdom_element apbdom_start) public subroutine of_buildtree (pbdom_object apbdom_obj[], long al_parent) public subroutine of_loadfromfile (string as_filename) end prototypes public subroutine wf_buildtree (pbdom_object apbdom_obj[], long al_parent);//Display XML Document in a TreeView /* Parameters: pbdom_object apbdom_Obj[] long al_Parent */ PBDOM_Object lpbdom_Children[] PBDOM_Attribute lpbdom_Attr[] PBDOM_Element lpbdom_Element Long ll_Handle Integer li_Counter, li_Max, li_AttrCounter, li_AttrMax String ls_Disp li_Max = UpperBound(apbdom_Obj) // Loop through all elements in the array For li_Counter = 1 To li_Max ls_Disp = "" // Get tag information depeding on type of entry Choose Case apbdom_Obj[li_Counter].GetObjectClassString() Case "pbdom_processinginstruction" ls_Disp = ": " + apbdom_Obj[li_Counter].Dynamic GetData() Case "pbdom_text" ls_Disp = ": " + apbdom_Obj[li_Counter].Dynamic GetText() Case "pbdom_element" // An element might have attributes lpbdom_Element = apbdom_Obj[li_Counter] If lpbdom_Element.HasAttributes() Then lpbdom_Element. GetAttributes(lpbdom_Attr) li_AttrMax = UpperBound(lpbdom_Attr) // Loop through all attributes For li_AttrCounter = 1 To li_AttrMax ls_Disp = ls_Disp + lpbdom_Attr[li_AttrCounter].GetName()+ "=" + lpbdom_Attr[li_AttrCounter].GetText()+ " " Next ls_Disp = ": " + ls_Disp End If Case Else ls_Disp = ": " + apbdom_Obj[li_Counter].GetText() End Choose // Display name + additional information ls_Disp = apbdom_Obj[li_Counter].GetName()+ ls_Disp ll_Handle = tv_1.InsertItemLast(al_Parent,ls_Disp,0) // if object has children call the same function If apbdom_Obj[li_Counter].HasChildren() Then apbdom_Obj[li_Counter].GetContent(lpbdom_Children) wf_BuildTree(lpbdom_Children,ll_Handle) tv_1.ExpandItem(ll_Handle) End If Next Return end subroutine public function long wf_createtv (pbdom_object a_obj_node, boolean isfirst, long parenthandle, long handle);PBDOM_OBJECT l_objA_node[] PBDOM_Attribute l_attrA_node[] Long l_l_count_node,l_l_tot_attr,l_l_attr_loop,l_l_loop String tvLabel,l_s_orginal_objType Long tvHandle,tvChildHandle, tvChildHandleRet Long i Boolean lb_noneBefore Try // Get the childs of the node a_obj_node.GetContent(l_objA_node[]) l_s_orginal_objType = a_obj_node.GetObjectClassString() l_l_count_node = UpperBound(l_objA_node[]) // If it is leaf label node then there will be no child If IsNull(l_objA_node) Then l_l_count_node = 0 If l_l_count_node = 0 Then If Lower(l_s_orginal_objType) = "pbdom_element" Then //input/textarea tvLabel = "<" + a_obj_node.GetName() a_obj_node.Dynamic GetAttributes(l_attrA_node) If UpperBound(l_attrA_node) > 0 Then l_l_tot_attr = UpperBound(l_attrA_node) For l_l_attr_loop = 1 To l_l_tot_attr tvLabel += " " + l_attrA_node[l_l_attr_loop].GetName() + " = " + l_attrA_node[l_l_attr_loop].GetText() Next End If End If Boolean lb_add lb_add = True If Lower(l_s_orginal_objType) = "pbdom_element" Then tvLabel += ">" + " " + " " Else // a_obj_node.GetName() -> #text + " " + Name: String ls_text ls_text = Trim(a_obj_node.GetText()) Do While Pos(ls_text, "~n") > 0 ls_text = Replace(ls_text, Pos(ls_text, "~n"), 1, "") Loop If Len(ls_text) > 0 Then tvLabel += a_obj_node.GetName() + " " + ls_text Else lb_add = False End If End If If lb_add = True Then If isFirst Then tvHandle = tv_1.InsertItemFirst(ParentHandle, tvLabel, 2) Else tvHandle = tv_1.InsertItem(ParentHandle, Handle, tvLabel, 2) End If End If tv_1.ExpandItem(tvHandle) Return tvHandle Else If Lower(l_s_orginal_objType) = "pbdom_element" Then // Select tvLabel = "<" + a_obj_node.GetName() a_obj_node.Dynamic GetAttributes(l_attrA_node) If UpperBound(l_attrA_node) > 0 Then l_l_tot_attr = UpperBound(l_attrA_node) For l_l_attr_loop = 1 To l_l_tot_attr tvLabel += " " + l_attrA_node[l_l_attr_loop].GetName() + " = " + l_attrA_node[l_l_attr_loop].GetText() Next Else tvLabel += " " End If End If If Lower(l_s_orginal_objType) = "pbdom_element" Then tvLabel += ">" + " " Else tvLabel += a_obj_node.GetName() + " " End If If isFirst Then tvHandle = tv_1.InsertItemFirst(ParentHandle, tvLabel, 2) Else tvHandle = tv_1.InsertItem(ParentHandle, Handle, tvLabel, 2) End If lb_noneBefore = True For l_l_loop = 1 To l_l_count_node If l_l_loop = 1 Or lb_noneBefore = True Then tvChildHandleRet = wf_createtv( l_objA_node[l_l_loop], True, tvHandle, 0) If tvChildHandleRet > 0 Then tvChildHandle = tvChildHandleRet lb_noneBefore = False End If Else tvChildHandleRet = wf_createtv( l_objA_node[l_l_loop], False, tvHandle, tvChildHandle) If tvChildHandleRet > 0 Then tvChildHandle = tvChildHandleRet lb_noneBefore = False End If End If Next tv_1.ExpandItem(tvHandle) Return 1 End If Catch ( PBDOM_EXCEPTION my_exp ) MessageBox("test",my_exp.GetMessage()) End Try end function public function boolean of_findelementwithattributevalue (pbdom_element apbdom_found, string as_element, string as_attribute, string as_value, pbdom_element apbdom_start);Boolean lb_Found PBDOM_Object lpbdom_Obj[] PBDOM_Attribute lpbdom_Attrib[] PBDOM_Element lpbdom_Element String ls_Attribute Long ll_Counter, ll_Max Integer li_Counter, li_Max apbdom_Start.GetContent( lpbdom_Obj ) ll_Max = UpperBound( lpbdom_Obj ) // Loop over all objects For ll_Counter = 1 To ll_Max If lpbdom_Obj[ ll_Counter ].GetObjectClassString() = "pbdom_element" Then // Element found -> Check for Attributes and Values lpbdom_Element = lpbdom_Obj[ ll_Counter ] If Lower( lpbdom_Element.GetName() ) = Lower( as_Element ) Then // Get Attributes lpbdom_Element.GetAttributes( lpbdom_Attrib) li_Max = UpperBound( lpbdom_Attrib ) // Loop over all Attributes For li_Counter = 1 To li_Max ls_Attribute = lpbdom_Attrib[ li_Counter ].GetName( ) If Lower( ls_Attribute ) = Lower( as_Attribute ) Then // Check if Attribute found If lpbdom_Element.GetAttributeValue ( ls_Attribute ) = as_Value Then // If Attribute found, check for Value apbdom_Found = lpbdom_Obj[ ll_Counter ] lb_Found = True Exit End If End If Next End If If Not lb_Found And lpbdom_Element.HasChildren() Then // If not found, dig deeper lb_Found = This.of_FindElementWithAttributeValue( apbdom_Found, as_Element, as_Attribute, as_Value, lpbdom_Element ) End If End If If lb_Found Then Exit End If Next Return lb_Found end function public subroutine of_buildtree (pbdom_object apbdom_obj[], long al_parent);PBDOM_Object lpbdom_Children[] PBDOM_Attribute lpbdom_Attr[] Long ll_Handle Integer li_Counter, li_Max, li_AttrCounter, li_AttrMax String ls_Disp li_Max = UpperBound( apbdom_Obj ) // Loop through all elements in the array For li_Counter = 1 To li_Max ls_Disp = "" // Get tag information depeding on type of entry Choose Case apbdom_Obj[ li_Counter].GetObjectClassString() Case "pbdom_processinginstruction" ls_Disp = ": " + apbdom_Obj[ li_Counter].Dynamic GetData() Case "pbdom_text" ls_Disp = ": " + apbdom_Obj[ li_Counter].Dynamic GetText() Case "pbdom_element" // An element might have attributes If apbdom_Obj[ li_Counter].Dynamic HasAttributes() Then apbdom_Obj[ li_Counter].Dynamic GetAttributes( lpbdom_Attr ) li_AttrMax = UpperBound( lpbdom_Attr ) // Loop through all attributes For li_AttrCounter = 1 To li_AttrMax ls_Disp = ls_Disp + lpbdom_Attr[ li_AttrCounter ].GetName() + "=" + lpbdom_Attr[ li_AttrCounter ].GetText() + " " Next ls_Disp = ": " + ls_Disp End If Case Else ls_Disp = ": " + apbdom_Obj[ li_Counter ].GetText() End Choose // Display name + additional information ls_Disp = apbdom_Obj[ li_Counter ].GetName() + ls_Disp ll_Handle = tv_1.InsertItemLast( al_Parent, ls_Disp, 0 ) // If the object has children call the same function again If apbdom_Obj[ li_Counter ].HasChildren() Then apbdom_Obj[ li_Counter ].GetContent( lpbdom_Children ) of_BuildTree( lpbdom_Children, ll_Handle ) tv_1.ExpandItem( ll_Handle ) End If Next Return end subroutine public subroutine of_loadfromfile (string as_filename);PBDOM_Builder lpbdom_Builder PBDOM_Document lpbdom_Doc PBDOM_Object lpbdom_Obj[] PBDOM_Element lpbdom_Root Integer li_Counter, li_Max String ls_Text // Create PBDOM Builder lpbdom_Builder = Create PBDOM_Builder Try // Import File and generate XML Document lpbdom_Doc = lpbdom_Builder.BuildFromFile( as_FileName ) Catch (PBDOM_Exception lpbdom_Except) // Error Handling goes here, MessageBox( "PBDOM_Exception", lpbdom_Except.GetExceptionCode()) Return End Try // Get 1st Level data lpbdom_Doc.GetContent( lpbdom_Obj ) li_Max = UpperBound( lpbdom_Obj ) For li_Counter = 1 To li_Max ls_Text = ls_Text + "~r~n" + lpbdom_Obj[ li_Counter ].GetObjectClassString() + ": " + lpbdom_Obj[ li_Counter ].GetName() Next lpbdom_Root = lpbdom_Doc.GetRootElement( ) ls_Text = ls_Text + "~r~n" + lpbdom_Root.GetObjectClassString() + ": " + lpbdom_Root.GetName() //st_disp.Text = ls_Text Destroy lpbdom_Builder of_BuildTree( lpbdom_Obj, 0 ) PBDOM_Element lpbdom_Customer, lpbdom_Order, lpbdom_OrderDate, lpbdom_OrderRegion If of_FindElementWithAttributeValue( lpbdom_Customer, "CUSTOMER", "ID", "102", lpbdom_Doc.GetRootElement() ) Then Try // Create sales order lpbdom_Order = Create PBDOM_Element lpbdom_Order.SetName( "SALESORDER" ) lpbdom_Order.SetAttribute( "ID", "111" ) // Set Order ID // Create order date lpbdom_OrderDate = Create PBDOM_Element lpbdom_OrderDate.SetName( "ORDERDATE" ) lpbdom_OrderDate.SetText( "2004-12-31" ) // Create order region lpbdom_OrderRegion = Create PBDOM_Element lpbdom_OrderRegion.SetName( "ORDERREGION" ) lpbdom_OrderRegion.SetText( "Switzerland" ) // Add elements to sales order lpbdom_Order.AddContent( lpbdom_OrderDate ) lpbdom_Order.AddContent( lpbdom_OrderRegion ) // Add sales order to customer lpbdom_Customer.AddContent( lpbdom_Order ) Catch (PBDOM_Exception lpbdom_Except2) // Error Handling goes here, MessageBox( "PBDOM_Exception", lpbdom_Except2.GetExceptionCode()) Return End Try End If PBDOM_Element lpbdom_Delete If of_FindElementWithAttributeValue( lpbdom_Delete, "CUSTOMER", "ID", "101", lpbdom_Doc.GetRootElement() ) Then Try lpbdom_Delete.Detach() Catch (PBDOM_Exception lpbdom_Except3) // Error Handling goes here, MessageBox( "PBDOM_Exception", lpbdom_Except3.GetExceptionCode()) Return End Try End If lpbdom_Doc.SaveDocument( "Saved.xml" ) Return end subroutine on w_main.create this.cb_9=create cb_9 this.cb_8=create cb_8 this.cb_7=create cb_7 this.cb_6=create cb_6 this.cb_5=create cb_5 this.cb_4=create cb_4 this.tv_1=create tv_1 this.cb_3=create cb_3 this.cb_2=create cb_2 this.mle_1=create mle_1 this.cb_1=create cb_1 this.Control[]={this.cb_9,& this.cb_8,& this.cb_7,& this.cb_6,& this.cb_5,& this.cb_4,& this.tv_1,& this.cb_3,& this.cb_2,& this.mle_1,& this.cb_1} end on on w_main.destroy destroy(this.cb_9) destroy(this.cb_8) destroy(this.cb_7) destroy(this.cb_6) destroy(this.cb_5) destroy(this.cb_4) destroy(this.tv_1) destroy(this.cb_3) destroy(this.cb_2) destroy(this.mle_1) destroy(this.cb_1) end on type cb_9 from commandbutton within w_main integer x = 64 integer y = 884 integer width = 869 integer height = 112 integer taborder = 70 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" string text = "Read XML Document 2" end type event clicked;PBDOM_BUILDER pbdom_build PBDOM_DOCUMENT pbdom_doc PBDOM_ELEMENT pbdom_elem_root,pbdbom_elem[],pbdbom_elem1[] PBDOM_OBJECT pbdom_obj[] String ls_data,ls_a[] Integer i,j Try pbdom_build = Create PBDOM_BUILDER pbdom_doc = pbdom_build.buildfromfile('05052482.xml') Catch (PBDOM_EXCEPTION pbdom_except) MessageBox('Exceptioin',pbdom_except.Text) Return End Try pbdom_elem_root = pbdom_doc.getrootelement() pbdom_elem_root.getcontent(pbdbom_elem[]) //Get element array For i = 1 To UpperBound(pbdbom_elem[]) //<SENDER> ls_data = pbdbom_elem[1].GetText() //Get element value //<RECEIVER> ls_data = pbdbom_elem[2].GetText() //<MSGSENDDATE> ls_data = pbdbom_elem[3].GetText() //<HEADER> pbdbom_elem[4].getcontent(pbdbom_elem1[]) // check loop For j = 1 To UpperBound(pbdbom_elem1[]) //<DOCPURPOSE> ls_data = pbdbom_elem1[1].GetText() //<ORDERTYPE> ls_data = pbdbom_elem1[2].GetText() //<ORDERNUM> ls_data = pbdbom_elem1[3].GetText() //<SALESTERM> ls_data = pbdbom_elem1[4].GetText() //<PURCURRENCY> ls_data = pbdbom_elem1[5].GetText() //<CUSTORDNUM> ls_data = pbdbom_elem1[6].GetText() //<FOBPOINT> ls_data = pbdbom_elem1[7].GetText() //<DIVISION> ls_data = pbdbom_elem1[8].GetText() //<DOCPURPOSE> ls_data = pbdbom_elem1[9].GetText() //<DATEINFO> pbdbom_elem1[10].getcontent(pbdom_obj[]) //<DATETYPE> ls_data = pbdbom_elem1[10].getchildelement(pbdom_obj[1].GetName()).GetText() //<DATE> ls_data = pbdbom_elem1[10].getchildelement(pbdom_obj[2].GetName()).GetText() //<SHIPINFO> ls_data = pbdbom_elem1[11].getattributevalue('PARENT') //Get attributes pbdbom_elem1[11].getcontent(pbdom_obj[]) Next Next MessageBox('',ls_data) Destroy pbdom_build end event type cb_8 from commandbutton within w_main integer x = 64 integer y = 620 integer width = 869 integer height = 112 integer taborder = 70 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" string text = " XML Document To TreeView 3" end type event clicked;String path, Filename, fullfilename GetFileOpenName ( "Select an XML File to Read", path, Filename , "XML", "XML Data, *.XML" ) fullfilename = path Long ll_ret String ls_err ll_ret = XMLParseFile(Filename, ls_err) If ll_ret <> 0 Then MessageBox("Error in XMLM file", ls_err) Return End If of_LoadFromFile( Filename) end event type cb_7 from commandbutton within w_main integer x = 64 integer y = 1016 integer width = 869 integer height = 112 integer taborder = 60 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" string text = "Create XML Using PBDOM 2" end type event clicked;Try PBDOM_ELEMENT pbdom_elem_1 PBDOM_ELEMENT pbdom_elem_2 PBDOM_ELEMENT pbdom_elem_3 PBDOM_ELEMENT pbdom_elem_4 PBDOM_DOCUMENT pbdom_doc1 pbdom_attribute pbdom_attr1 String ls_xml pbdom_doc1 = Create PBDOM_DOCUMENT pbdom_elem_1 = Create PBDOM_ELEMENT pbdom_elem_2 = Create PBDOM_ELEMENT pbdom_elem_3 = Create PBDOM_ELEMENT pbdom_elem_4 = Create PBDOM_ELEMENT pbdom_attr1 = Create pbdom_attribute pbdom_attr1.setName("attribute1") pbdom_elem_1.SetName("pbdom_elem_1") //pbdom_elem_1.SetText( "this is the pbdom_elem_1" ) //pbdom_elem_1.SetAttribute("attr1:test", "attr1_testing") pbdom_elem_1.SetAttribute("attr12", "attr1_testing2") pbdom_attr1.SetName ("a") pbdom_attr1.SetNamespace ("pre2", "http://www.pre.com", False) pbdom_attr1.SetText("456") pbdom_elem_1.SetAttribute(pbdom_attr1) pbdom_elem_2.SetName("pbdom_elem_2") pbdom_elem_2.SetText( "this is the pbdom_elem_2" ) pbdom_elem_3.SetName("pbdom_elem_3") //pbdom_elem_3.SetText( "this is the pbdom_elem_3" ) pbdom_elem_4.SetName("pbdom_elem_4") pbdom_elem_4.SetText( "this is the pbdom_elem_4" ) pbdom_elem_3.AddContent(pbdom_elem_4) pbdom_elem_1.AddContent(pbdom_elem_2) pbdom_elem_1.AddContent(pbdom_elem_3) pbdom_doc1.NewDocument("", "", "Root_Element", "", "") // pbdom_doc1.NewDocument ("pre", "http://www.pre.com", "root", "public_id", "system_id.dtd") pbdom_doc1.GetRootElement().Detach() pbdom_doc1.AddContent(pbdom_elem_1) ls_xml = pbdom_doc1.SaveDocumentIntoString() mle_1.text = ls_xml Catch (pbdom_exception ex) MessageBox("Exception", ex.getMessage()) End Try end event type cb_6 from commandbutton within w_main integer x = 64 integer y = 752 integer width = 869 integer height = 112 integer taborder = 50 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" string text = "Read XML Document" end type event clicked;PBDOM_BUILDER pbdom_bldr PBDOM_Document pbdom_doc PBDOM_Object pbdom_obj_array[] PBDOM_Element pbdom_elem Integer iFileNum1 Long l = 0 Try // Create a PBDOM_DOCUMENT from the XML file pbdom_bldr = Create PBDOM_BUILDER pbdom_doc = pbdom_bldr.BuildFromFile ("pbdom_doc_1.xml") // Test the contents of the PBDOM_DOCUMENT // First test the PBDOM_DOCTYPE in the document MessageBox ("PBDOM_DOCTYPE GetName()", pbdom_doc.GetDocType().GetName()) MessageBox ("PBDOM_DOCTYPE GetInternalSubset()", pbdom_doc.GetDocType().GetInternalSubset()) // Test the root element MessageBox ("PBDOM_DOC Root Element Name", pbdom_doc.GetRootElement().GetName()) // test the root element's child element MessageBox ("PBDOM_DOC <data> Element Name", pbdom_doc.GetRootElement().GetChildElement("data").GetName()) // Collect all the child PBDOM_OBJECTs of the // <data> element pbdom_doc.GetRootElement().GetChildElement("data").GetContent(pbdom_obj_array) // Display the class name, the name and the text contained // within each PBDOM_OBJECT array item For l = 1 To UpperBound(pbdom_obj_array) MessageBox ("Child Object " + String(l) + " Class",pbdom_obj_array[l].GetObjectClassString()) MessageBox ("Child Object " + String(l) + " Name", pbdom_obj_array[l].GetName()) MessageBox ("Child Object " + String(l) + " Text",pbdom_obj_array[l].GetText()) Next // save the DOM Tree contained within pbdom_doc into // a separate file "c:/pbdom_doc_2.xml" pbdom_doc.SaveDocument ("pbdom_doc_2.xml") Destroy pbdom_bldr Catch (PBDOM_Exception except) MessageBox ("Exception Occurred", except.Text) End Try end event type cb_5 from commandbutton within w_main integer x = 64 integer y = 488 integer width = 869 integer height = 112 integer taborder = 40 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" string text = " XML Document To TreeView 2" end type event clicked;Int i,j Int outersize, innersize String path, Filename, fullfilename PBDOM_DOCUMENT iPBDOM_doc PBDOM_BUILDER iPBDomBuilder OLEObject iole_xml_document iPBDomBuilder = Create PBDOM_BUILDER GetFileOpenName ( "Select an XML File to Read", path, Filename , "XML", "XML Data, *.XML" ) fullfilename = path Long ll_ret String ls_err ll_ret = XMLParseFile(Filename, ls_err) If ll_ret <> 0 Then MessageBox("Error in XMLM file", ls_err) Return End If Try tv_1.DeleteItem(0) iPBDOM_doc = iPBDomBuilder.buildfromfile(Filename ) wf_createtv( iPBDOM_doc,True,0,0) tv_1.ExpandItem(0) Catch (PBDOM_EXCEPTION e) MessageBox ("Exception in Building Treeview", e.Text) End Try end event type cb_4 from commandbutton within w_main integer x = 64 integer y = 356 integer width = 869 integer height = 112 integer taborder = 30 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" string text = " XML Document To TreeView" end type event clicked;PBDOM_Builder lpbdom_Builder PBDOM_Document lpbdom_Doc PBDOM_Object lpbdom_Obj[] PBDOM_Element lpbdom_Root Integer li_Counter, li_Max String ls_Text String path, Filename, fullfilename GetFileOpenName ( "Select an XML File to Read", path, Filename , "XML", "XML Data, *.XML" ) fullfilename = path Long ll_ret String ls_err ll_ret = XMLParseFile(Filename, ls_err) If ll_ret <> 0 Then MessageBox("Error in XMLM file", ls_err) Return End If // Create PBDOM Builder lpbdom_Builder = Create PBDOM_Builder Try // Import File and generate XML Document lpbdom_Doc = lpbdom_Builder.BuildFromFile(Filename ) Catch (PBDOM_Exception lpbdom_Except) // Error Handling goes here, MessageBox( "PBDOM_Exception", lpbdom_Except.GetExceptionCode()) Return End Try // Get 1st Level data lpbdom_Doc.GetContent( lpbdom_Obj ) wf_buildtree(lpbdom_Obj , 0) end event type tv_1 from treeview within w_main integer x = 2459 integer y = 172 integer width = 997 integer height = 1460 integer taborder = 30 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 borderstyle borderstyle = stylelowered! long picturemaskcolor = 536870912 long statepicturemaskcolor = 536870912 end type type cb_3 from commandbutton within w_main integer x = 64 integer y = 224 integer width = 869 integer height = 112 integer taborder = 20 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" string text = "Create XML Using OleObject" end type event clicked;oleobject lole_dom, lole_root, lole_element1, lole_element11, lole_element12 String ls_result // build DOM (you don't need this if you use PBDOM) lole_dom = Create oleobject lole_dom.ConnectToNewObject ("Msxml2.DOMDocument") lole_root = lole_dom.CreateElement ("NodeRoot") lole_dom.documentElement = lole_root lole_element1 = lole_dom.CreateElement("Node1") lole_root.AppendChild(lole_element1) lole_element1.SetAttribute("Attr", "AttrValue") lole_element11 = lole_dom.CreateElement("Node11") lole_element11.AppendChild (lole_dom.CreateTextNode("Here is a value")) lole_element1.AppendChild(lole_element11) lole_element12 = lole_dom.CreateElement("Node12") lole_element12.AppendChild (lole_dom.CreateTextNode("Here is another value")) lole_element1.AppendChild(lole_element12) // this saves the DOM without formatting //lole_dom.save ("testxml.xml") ls_result = lole_dom.xml mle_1.Text = ls_result Destroy lole_dom end event type cb_2 from commandbutton within w_main integer x = 1088 integer y = 36 integer width = 910 integer height = 112 integer taborder = 30 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" string text = "Formating XML Using OleObject" end type event clicked;oleobject lole_dom oleobject lole_Writer, lole_saxreader String ls_result If Len(mle_1.Text) < 1 Then Return // build DOM (you don't need this if you use PBDOM) lole_dom = Create oleobject lole_dom.ConnectToNewObject ("Msxml2.DOMDocument") //lole_dom.Load("D:\MyCode\PMIT\PBDOMXML\testxml.xml") Load From File lole_dom.loadXML(mle_1.Text) // this part is for formating lole_Writer = Create oleobject lole_saxreader = Create oleobject lole_Writer.ConnectToNewObject ("MSXML2.MXXMLWriter") lole_saxreader.ConnectToNewObject ("MSXML2.SAXXMLReader") lole_Writer.omitXMLDeclaration = True lole_Writer.Indent = True lole_saxreader.contentHandler = lole_Writer // instead of DOM you can also put a XML string to parser: lole_saxreader.parse ("<node>...</node>") // so you can also use the PBDOM output directly lole_saxreader.parse (lole_dom) // here is your formatted output ls_result = lole_Writer.output mle_1.Text = ls_result lole_Writer.DisconnectObject( ) lole_saxreader.DisconnectObject( ) lole_dom.DisconnectObject( ) Destroy lole_Writer Destroy lole_saxreader Destroy lole_dom end event type mle_1 from multilineedit within w_main integer x = 1093 integer y = 172 integer width = 1321 integer height = 1460 integer taborder = 20 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 boolean hscrollbar = true boolean vscrollbar = true boolean autohscroll = true boolean autovscroll = true borderstyle borderstyle = stylelowered! end type type cb_1 from commandbutton within w_main integer x = 64 integer y = 92 integer width = 869 integer height = 112 integer taborder = 10 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" string text = "Create XML Using PBDOM" end type event clicked;String ls_xml PBDOM_Document doc PBDOM_Element noderoot, node1, node11, node12 doc = Create PBDOM_Document doc.NewDocument("NodeRoot") noderoot = doc.GetRootElement() node1 = Create PBDOM_Element node1.SetName("Node1") noderoot.AddContent(node1) node1.SetAttribute("Attr", "AttrValue") node11 = Create PBDOM_Element node11.SetName("Node11") node11.AddContent("Here is a value") node1.AddContent(node11) node12 = Create PBDOM_Element node12.SetName("Node12") node12.AddContent("Here is another value") node1.AddContent(node12) doc.SaveDocument("myDoc.xml") ls_xml = doc.SaveDocumentIntoString() mle_1.Text = ls_xml end event |
Find Projects On Github click here
Good Luck!
this is great help .