on 08-29-2006 10:27 AM
Hi,
I have a context with topnode "ship" (cardinality 1..n, singleton true) and a childnode "voyage" (cardinality 0..n , singleton true).
ship (node 1..n)
...Voyage (node 0..n)
......Date (attr)
......Port (attr)
......{etc...}
...vesselname (attr)
The problem occurs when I read an XML file from Lotus Domino (via ReadViewEntries) and I try to put that data into the described context. The result in my case is that it only reads all the entries and seemingly doesn't "group" them in a proper way.
I'm using SAX to parse the XML.
In pseudo it would be like:
- create shipelement (at shipinfo in XML file)
- get vesselname and add shipelement to shipnode
- create voyagelement (at voyageinfo in XML file)
- get attributes
- add voyagelement to voyagenode (of shipnode)
So what I'm struggling with here is not actually the parsing (but any pointers here will also be rewarded of course!), but rather the structuring of the nodes and binding of elements. Also, I'm not quite sure how to make the dropdownbox update the contents of the table (but this may be solved if my first problem is solved).
I looked at the tutorial for master/detail view and it had some sort of supplymethod to fill the table on demand. I want to do the same, but all my data is already loaded into the context, and I think I just have to alter the lead_selection for each select in the dropdownbox. But how to do this?
Here is the code (sorry about the crappy format):
public void startElement(String namespaceURI, String localName, String rawName, Attributes atts) {
getChars = false;
if (rawName.equals("viewentry")) {
numChildren = (atts.getValue("children"));
unid = atts.getValue("unid");
noteid = atts.getValue("noteid");
if (numChildren != null && !numChildren.equals("")) {
isShipNode = true;
isVoyageNode = false;
shipElement = wdContext.createShipElement();
wdContext.nodeShip().addElement(shipElement);
//shipNode = wdContext.createShipElement();
//wdContext.nodeShip().addElement(shipNode);
}
else if (unid != null && !unid.equals("")) {
//we have voyageentry
isShipNode = false;
isVoyageNode = true;
voyageElement = wdContext.createVoyageElement();
voyageElement.setUNID(unid);
voyageElement.setNOTEID(noteid);
wdContext.nodeShip().nodeVoyage().addElement(voyageElement);
}
}
else if (rawName.equals("entrydata")) {
if (isVoyageNode && !isShipNode) {
lastAttribute = atts.getValue("name");
}
else if (isShipNode && !isVoyageNode) {
}
}
else if (rawName.equals("text")) {
getChars = true;
datatype = DATATYPE_STRING;
}
else if (rawName.equals("number")) {
getChars = true;
datatype = DATATYPE_STRING;
}
else if (rawName.equals("datetime")) {
getChars = true;
datatype = DATATYPE_DATE;
}
}
public void characters(char[] data, int off, int length) {
String tmp = new String(data, off, length).trim();
Object input = null;
if (tmp.length() > 0) {
if (isShipNode && getChars) {
shipElement.setVESSEL_NAME(tmp);
getChars = false;
}
else if (isVoyageNode && getChars) {
if (lastAttribute.equals("$1")) {
voyageElement.setAttributeValue("VOYAGEID", tmp);
}
else if (lastAttribute.equals("$2")) {
voyageElement.setAttributeValue("ICON", tmp);
}
else if (lastAttribute.equals("$3")) {
//DO nothing
}
else {
if (datatype == DATATYPE_DATE) {
try {
Date d = DateFormat.getDateTimeInstance().parse(tmp);
input = DateFormat.getDateTimeInstance().format(d);
}
catch (ParseException e) {
input = "Not parseable: " + tmp;
e.printStackTrace();
}
}
else if (datatype == DATATYPE_STRING) {
input = tmp;
}
else if (datatype == DATATYPE_INT) {
input = new Double(tmp);
}
else {
input = tmp;
}
voyageElement.setAttributeValue(lastAttribute, input);
}
}
}
}
public void endElement(String namespaceURI, String localName, String rawName) {
if (rawName.equals("viewentry")) {
//shipNode = null;
//lastAttribute = null;
if (isShipNode) {
shipElement = null;
isShipNode = !isShipNode;
}
if (isVoyageNode) {
voyageElement = null;
isVoyageNode = !isVoyageNode;
//shipNode = null;
//voyageNode = null;
}
}
else if (rawName.equals("entrydata")) {
}
}
The XML data:
-
Best Regards,
Hans Petter Bjørn
Hans,
Seems that you have to make node <b>voyage</b> non-singleton. And populate it like this:
IShipElement lastShipAdded = wdContext.nodeShip()
.getShipElementAt( wdContext.nodeShip().size() - 1);
voyageElement = lastShipAdded.nodeVoyage()
.createVoyageElement();
voyageElement.setUNID(unid);
voyageElement.setNOTEID(noteid);
lastShipAdded.nodeVoyage()
.addElement(voyageElement);
Valery Silaev
EPAM Systems
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
95 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.