I have an agent in Java that parse XML files in a Body field, creating Notes documents based on the content of the XML file.
I can read the Nodes values, but not the attributes. What code needs to be added to read attributes of a Node? Code below works fine, except reading attr. (As I’m bad at Java I have no idea how to)
example of attribute is currency below:
import lotus.domino.*;
import java.util.*;
public class JavaAgent extends AgentBase
{
public void NotesMain()
{
try
{
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
// (Your code goes here)
Database db=agentContext.getCurrentDatabase();
//get reference to documents with xml attachments
DocumentCollection collection=agentContext.getUnprocessedDocuments();
Document doc=collection.getFirstDocument();
while(doc!=null)
{
RichTextItem body=(RichTextItem)doc.getFirstItem("Body");
//get reference to xml attachment
Vector objects=body.getEmbeddedObjects();
for (int i = 0; i < objects.size() ; i++)
{
EmbeddedObject emo = (EmbeddedObject)objects.get(i);
if(emo.getType()==EmbeddedObject.EMBED_ATTACHMENT)
{
//parse xml attahcment and create dom Document object
org.w3c.dom.Document document=emo.parseXML(false);
//get reference to root element SalesOrder
org.w3c.dom.Element rootElement=document.getDocumentElement();
//get reference to order child nodes
org.w3c.dom.NodeList orders=rootElement.getElementsByTagName("Order");
for(int j=0; j < orders.getLength(); j++)
{
org.w3c.dom.Node order=orders.item(j);
//create notes order document
Document orderDoc=db.createDocument();
orderDoc.replaceItemValue("Form", "Order");
//get reference to all order details: order id, item and quantity
org.w3c.dom.NodeList orderDetails=order.getChildNodes();
for(int k=0; k < orderDetails.getLength(); k++)
{
//replace field values with order details
org.w3c.dom.Node orderDetail=orderDetails.item(k);
if(orderDetail.getNodeName().equals("Id"))
orderDoc.replaceItemValue("OrderId", orderDetail.getFirstChild().getNodeValue());
else if(orderDetail.getNodeName().equals("Item"))
orderDoc.replaceItemValue("Item", orderDetail.getFirstChild().getNodeValue());
else if(orderDetail.getNodeName().equals("Quantity"))
orderDoc.replaceItemValue("Quantity", orderDetail.getFirstChild().getNodeValue());
}
orderDoc.save(false, false);
}
}
}
doc=collection.getNextDocument(doc);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}