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.


This was first published in January 2001

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

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.