Home > Domino Tips > Developer > LotusScript > XML import
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

LOTUSSCRIPT

XML import


Kester Simm
01.10.2001
Rating: --- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


View member feedback to this tip.

You don't need to be a Java hacker to be able to work with XML parsing and working. This can be seen by looking at various examples of the sandbox.

If you use the Microsoft XML parser on your server, you can work with XML on your Domino server. The good thing about the script you use for the Microsoft parser is that you don't need to change much if you are going to use LotusScript server-side or Javascript client side.

For tips on XML, XLS, DOM and other SE sites: http://www.w3schools.com/default.asp

In my code I created new documents from XML. The XML could come from anywhere -- in this case the sandbox ACME.nsf.

You could use this to simply move documents from one notes database to another, from another type of database, or to change fields. The XML document could be an embedded view on a page.

Code: the xml 
--------
<?xml version="1.0"?>
<partscatalog>
<part><partname>12 Volt Corded Spotlight</partname><partnumber>CS9586</partnumber><
manufacturer>Acme</manufacturer><stock>In
Stock</stock><regprice>15.77</regprice><saleprice>
13.83</saleprice></part><part><partname>Automotive
meter</partname><partnumber>AM8754</partnumber><
manufacturer>Acme</manufacturer><stock>In
Stock</stock><regprice>108.36</regprice><saleprice>
106.95</saleprice></part><part><partname>Gravity Feed
Spray Gun</partname><partnumber>GFSG2224</partnumber><
manufacturer>Acme</manufacturer><stock>In
Stock</stock><regprice>134.36</regprice><saleprice>
133.56</saleprice></part><part><partname>6X9 Inch 3-Way
160 Watt Speaker Set</partname><partnumber>SS4982</partnumber><
manufacturer>Acme</manufacturer><stock>In
Stock</stock><regprice>19.95</regprice><saleprice>
18.50</saleprice></part><part><partname>40 Watt Power
Booster</partname><partnumber>PB5423</partnumber><
manufacturer>Acme</manufacturer><stock>In
Stock</stock><regprice>14.95</regprice><saleprice>
</saleprice></part><part><partname>Digital Battery
Analyzer</partname><partnumber>BA85914o367a</partnumber>
<manufacturer>Acme</manufacturer><stock>In
Stock</stock><regprice>313.86</regprice><saleprice>
280.12</saleprice></part><part><partname>Ignition
Firing Indicator</partname><partnumber>IFI518764</partnumber>
<manufacturer>Acme</manufacturer><stock>In
Stock</stock><regprice>22.36</regprice><saleprice>
20.67</saleprice></part><part><partname>Engine Rebuild
Kits</partname><partnumber>RB98i0965</partnumber><
manufacturer>Acme</manufacturer><stock>In
Stock</stock><regprice>101.28</regprice><saleprice
>95.95</saleprice></part><part><partname>11-1/2"
Carburetor Linkage</partname><partnumber>CL856222</partnumber><
manufacturer>Acme</manufacturer><stock>In
Stock</stock><regprice>8.67</regprice><saleprice>
6.80</saleprice></part><part><partname>Acme Deluxe Fuel
Pump</partname><partnumber>DFP98402883</partnumber><
manufacturer>Acme</manufacturer><stock>In
Stock</stock><regprice>447.99</regprice><saleprice>
410.99</saleprice></part><part><partname>Acme Cam and
Lifter</partname><partnumber>ACL9978523</partnumber><
manufacturer>Acme</manufacturer><stock>In
Stock</stock><regprice>101.28</regprice><saleprice>
</saleprice></part><part><partname>Cordless
Drill</partname><partnumber>CD5894s</partnumber><
manufacturer>Acme</manufacturer><stock>In
Stock</stock><regprice>75.50</regprice><saleprice
></saleprice></part><part><partname>Electric Power
Washer</partname><partnumber>EPW85497</partnumber><
manufacturer>Acme</manufacturer><stock>In
Stock</stock><regprice>188.10</regprice><saleprice>
</saleprice></part><part><partname>5X7 Rectangular Light
Cover</partname><partnumber>RLC5871s</partnumber><
manufacturer>Acme</manufacturer><stock>In
Stock</stock><regprice>10.95</regprice><saleprice>
</saleprice></part><part><partname>Back-up
Lights</partname><partnumber>BL3321</partnumber><
manufacturer>Acme</manufacturer><stock>In
Stock</stock><regprice>95.42</regprice><saleprice>
85.95</saleprice></part> </partscatalog> -------- the script Sub Initialize Dim session As New notessession Dim db As notesdatabase Dim view As notesview Dim doc As notesdocument Dim source As Variant Dim XMLcount As Integer Dim Getpartname As Variant Dim Getpartnumber As Variant Dim Getmanufacturer As Variant Dim Getstock As Variant Dim Getregprice As Variant Dim Getsaleprice As Variant Set db=session.currentdatabase 'xml source file sourceFile="http://localhost/Acme.nsf/GetParts?OpenPage" 'This line creates the Microsoft.XMLDOM object. Set source = CreateObject("Microsoft.XMLDOM") source.async = False 'Sets the validateOnParse property to false 'source.validateOnParse =False 'This line loads the XML into the parser. source.load(sourceFile) XMLcount=CountElements(source,"partname") Getpartname=ElementsByTagName(source,"partname") Getpartnumber=ElementsByTagName(source,"partnumber") Getmanufacturer=ElementsByTagName(source,"manufacturer") Getstock=ElementsByTagName(source,"stock") Getregprice=ElementsByTagName(source,"regprice") Getsaleprice=ElementsByTagName(source,"saleprice") For i=1 To XMLcount Set doc = New NotesDocument( db ) doc.Form = "Import" doc.partname=Getpartname(i) doc.partnumber=Getpartnumber(i) doc.manufacturer=Getmanufacturer(i) doc.stock=Getstock(i) doc.regprice=Getregprice(i) doc.saleprice=Getsaleprice(i) doc.Kester=i Call doc.save(True,True) i=i+1 Next Msgbox ("'slut") End Sub Function CountElements(source,Tag As String)As Integer Set x=source.getElementsByTagName(Tag) CountElements=x.length End Function Function ElementsByTagName(source,Tag As String)As Variant Dim XMLList() As String Set x=source.getElementsByTagName(Tag) Redim XMLList(1 To x.length) For i = 1 To x.length XMLList(i)=(x.item(i-1).text) Next ElementsByTagName=XMLList End Function


MEMBER FEEDBACK TO THIS TIP

Excellent tip here but it erroneously retrieves every other xml element. Take away the i=i+1 in the for loop and it will retieve every element as intended.

-- David E.


Do you have comments of your own? Let us know.


Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
LotusScript
Eight easy steps to open and view Flash files in Lotus Notes
LotusScript agent parses ACL to Microsoft Notepad
LotusScript finds the first occurrence of a string from the right
Clear Recent Contacts view and prevent repopulation in Lotus Notes 8.x
Search Microsoft Active Directory with LotusScript
Three steps to trap and handle save conflicts with LotusScript
Troubleshoot agents by displaying LotusScript variables online
LotusScript sorts lists alphabetically
LotusScript code rebuilds corrupted busytime.nsf file
Soft-code item names to facilitate LotusScript management

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2010, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts