public static void writeXMLBIF03(String filename, String graphName, FastVector nodes, FastVector edges){ try { FileWriter outfile = new FileWriter(filename);  StringBuffer text = new StringBuffer();  text.append("<?xml version=\"1.0\"?>\n"); text.append("<!-- DTD for the XMLBIF 0.3 format -->\n"); text.append("<!DOCTYPE BIF [\n"); text.append("	<!ELEMENT BIF ( NETWORK )*>\n"); text.append("	      <!ATTLIST BIF VERSION CDATA #REQUIRED>\n"); text.append("	<!ELEMENT NETWORK ( NAME, ( PROPERTY | VARIABLE | DEFINITION )* )>\n"); text.append("	<!ELEMENT NAME (#PCDATA)>\n"); text.append("	<!ELEMENT VARIABLE ( NAME, ( OUTCOME |  PROPERTY )* ) >\n"); text.append("	      <!ATTLIST VARIABLE TYPE (nature|decision|utility) \"nature\">\n"); text.append("	<!ELEMENT OUTCOME (#PCDATA)>\n"); text.append("	<!ELEMENT DEFINITION ( FOR | GIVEN | TABLE | PROPERTY )* >\n"); text.append("	<!ELEMENT FOR (#PCDATA)>\n"); text.append("	<!ELEMENT GIVEN (#PCDATA)>\n"); text.append("	<!ELEMENT TABLE (#PCDATA)>\n"); text.append("	<!ELEMENT PROPERTY (#PCDATA)>\n"); text.append("]>\n"); text.append("\n"); text.append("\n"); text.append("<BIF VERSION=\"0.3\">\n"); text.append("<NETWORK>\n"); text.append("<NAME>" + XMLNormalize(graphName)  + "</NAME>\n");    for(int nodeidx=0; nodeidx<nodes.size(); nodeidx++) { GraphNode n = (GraphNode)nodes.elementAt(nodeidx); if(n.nodeType!=GraphNode.NORMAL) continue;  text.append("<VARIABLE TYPE=\"nature\">\n"); text.append("\t<NAME>" + XMLNormalize(n.ID) + "</NAME>\n");  if(n.outcomes!=null) for(int outidx=0; outidx<n.outcomes.length; outidx++) text.append("\t<OUTCOME>" + XMLNormalize(n.outcomes[outidx]) + "</OUTCOME>\n"); else text.append("\t<OUTCOME>true</OUTCOME>\n");  text.append("\t<PROPERTY>position = ("+n.x+","+n.y+")</PROPERTY>\n"); text.append("</VARIABLE>\n"); }     for (int nodeidx=0; nodeidx<nodes.size(); nodeidx++) { GraphNode n = (GraphNode) nodes.elementAt(nodeidx); if(n.nodeType!=GraphNode.NORMAL) continue;  text.append("<DEFINITION>\n"); text.append("<FOR>" + XMLNormalize(n.ID) + "</FOR>\n"); int parntOutcomes = 1; if(n.prnts!=null) for(int pidx=0; pidx<n.prnts.length; pidx++) { GraphNode prnt = (GraphNode)nodes.elementAt(n.prnts[pidx]); text.append("\t<GIVEN>" + XMLNormalize(prnt.ID) + "</GIVEN>\n"); if(prnt.outcomes!=null) parntOutcomes *= prnt.outcomes.length; }  text.append("<TABLE>\n"); for(int i=0; i<parntOutcomes; i++) { if(n.outcomes!=null) for(int outidx=0; outidx<n.outcomes.length; outidx++){ text.append(n.probs[i][outidx]+" "); } else text.append("1"); text.append('\n'); } text.append("</TABLE>\n"); text.append("</DEFINITION>\n"); }  text.append("</NETWORK>\n"); text.append("</BIF>\n");  outfile.write(text.toString()); outfile.close(); } catch(IOException ex) { ex.printStackTrace(); } }
public static void writeXMLBIF03(String filename, String graphName, FastVector nodes, FastVector edges) { try { FileWriter outfile = new FileWriter(filename);  StringBuffer text = new StringBuffer();  text.append("<?xml version=\"1.0\"?>\n"); text.append("<!-- DTD for the XMLBIF 0.3 format -->\n"); text.append("<!DOCTYPE BIF [\n"); text.append("	<!ELEMENT BIF ( NETWORK )*>\n"); text.append("	      <!ATTLIST BIF VERSION CDATA #REQUIRED>\n"); text.append("	<!ELEMENT NETWORK ( NAME, ( PROPERTY | VARIABLE | DEFI"+ "NITION )* )>\n"); text.append("	<!ELEMENT NAME (#PCDATA)>\n"); text.append("	<!ELEMENT VARIABLE ( NAME, ( OUTCOME |  PROPERTY )* )"+ " >\n"); text.append("	      <!ATTLIST VARIABLE TYPE (nature|decision|utility"+ ") \"nature\">\n"); text.append("	<!ELEMENT OUTCOME (#PCDATA)>\n"); text.append("	<!ELEMENT DEFINITION ( FOR | GIVEN | TABLE | PROPERTY"+ " )* >\n"); text.append("	<!ELEMENT FOR (#PCDATA)>\n"); text.append("	<!ELEMENT GIVEN (#PCDATA)>\n"); text.append("	<!ELEMENT TABLE (#PCDATA)>\n"); text.append("	<!ELEMENT PROPERTY (#PCDATA)>\n"); text.append("]>\n"); text.append("\n"); text.append("\n"); text.append("<BIF VERSION=\"0.3\">\n"); text.append("<NETWORK>\n"); text.append("<NAME>" + XMLNormalize(graphName)  + "</NAME>\n");     for(int nodeidx=0; nodeidx<nodes.size(); nodeidx++) { GraphNode n = (GraphNode)nodes.elementAt(nodeidx); if(n.nodeType!=GraphNode.NORMAL) continue;  text.append("<VARIABLE TYPE=\"nature\">\n"); text.append("\t<NAME>" + XMLNormalize(n.ID) + "</NAME>\n");  if(n.outcomes!=null) for(int outidx=0; outidx<n.outcomes.length; outidx++) text.append("\t<OUTCOME>" + XMLNormalize(n.outcomes[outidx])+ "</OUTCOME>\n"); else text.append("\t<OUTCOME>true</OUTCOME>\n");  text.append("\t<PROPERTY>position = ("+n.x+","+n.y+")</PROPERTY>\n"); text.append("</VARIABLE>\n"); }     for (int nodeidx=0; nodeidx<nodes.size(); nodeidx++) { GraphNode n = (GraphNode) nodes.elementAt(nodeidx); if(n.nodeType!=GraphNode.NORMAL) continue;  text.append("<DEFINITION>\n"); text.append("<FOR>" + XMLNormalize(n.ID) + "</FOR>\n"); int parntOutcomes = 1; if(n.prnts!=null) for(int pidx=0; pidx<n.prnts.length; pidx++) { GraphNode prnt = (GraphNode)nodes.elementAt(n.prnts[pidx]); text.append("\t<GIVEN>" + XMLNormalize(prnt.ID) + "</GIVEN>\n"); if(prnt.outcomes!=null) parntOutcomes *= prnt.outcomes.length; }  text.append("<TABLE>\n"); for(int i=0; i<parntOutcomes; i++) { if(n.outcomes!=null) for(int outidx=0; outidx<n.outcomes.length; outidx++){ text.append(n.probs[i][outidx]+" "); } else text.append("1"); text.append('\n'); } text.append("</TABLE>\n"); text.append("</DEFINITION>\n"); }  text.append("</NETWORK>\n"); text.append("</BIF>\n");  outfile.write(text.toString()); outfile.close(); } catch(IOException ex) { ex.printStackTrace(); } }
    public static void writeXMLBIF03(String filename, String graphName, FastVector nodes, FastVector edges){	try {	    FileWriter outfile = new FileWriter(filename);	    StringBuffer text = new StringBuffer();	    	    text.append("<?xml version=\"1.0\"?>\n");	    text.append("<!-- DTD for the XMLBIF 0.3 format -->\n");	    text.append("<!DOCTYPE BIF [\n");	    text.append("	<!ELEMENT BIF ( NETWORK )*>\n");	    text.append("	      <!ATTLIST BIF VERSION CDATA #REQUIRED>\n");	    text.append("	<!ELEMENT NETWORK ( NAME, ( PROPERTY | VARIABLE | DEFINITION )* )>\n");	    text.append("	<!ELEMENT NAME (#PCDATA)>\n");	    text.append("	<!ELEMENT VARIABLE ( NAME, ( OUTCOME |  PROPERTY )* ) >\n");	    text.append("	      <!ATTLIST VARIABLE TYPE (nature|decision|utility) \"nature\">\n");	    text.append("	<!ELEMENT OUTCOME (#PCDATA)>\n");	    text.append("	<!ELEMENT DEFINITION ( FOR | GIVEN | TABLE | PROPERTY )* >\n");	    text.append("	<!ELEMENT FOR (#PCDATA)>\n");	    text.append("	<!ELEMENT GIVEN (#PCDATA)>\n");	    text.append("	<!ELEMENT TABLE (#PCDATA)>\n");	    text.append("	<!ELEMENT PROPERTY (#PCDATA)>\n");	    text.append("]>\n");	    text.append("\n");	    text.append("\n");	    text.append("<BIF VERSION=\"0.3\">\n");	    text.append("<NETWORK>\n");	    text.append("<NAME>" + XMLNormalize(graphName)  + "</NAME>\n");	    	    //Writing all the node names and their outcomes	    //If outcome is null(ie if the graph was loaded from DOT file) then simply write TRUE	    for(int nodeidx=0; nodeidx<nodes.size(); nodeidx++) {		GraphNode n = (GraphNode)nodes.elementAt(nodeidx);		if(n.nodeType!=GraphNode.NORMAL)		    continue;		text.append("<VARIABLE TYPE=\"nature\">\n");		text.append("\t<NAME>" + XMLNormalize(n.ID) + "</NAME>\n");				if(n.outcomes!=null)		    for(int outidx=0; outidx<n.outcomes.length; outidx++) 			text.append("\t<OUTCOME>" + XMLNormalize(n.outcomes[outidx]) + "</OUTCOME>\n");		else		   text.append("\t<OUTCOME>true</OUTCOME>\n"); 				text.append("\t<PROPERTY>position = ("+n.x+","+n.y+")</PROPERTY>\n");		text.append("</VARIABLE>\n");	    }	    	    //Writing all the nodes definitions and their probability tables	    //If probability table is null then simply write 1 for all 	    //the posible outcomes of the parents	    for (int nodeidx=0; nodeidx<nodes.size(); nodeidx++) {		GraphNode n = (GraphNode) nodes.elementAt(nodeidx);		if(n.nodeType!=GraphNode.NORMAL)		    continue;		text.append("<DEFINITION>\n");		text.append("<FOR>" + XMLNormalize(n.ID) + "</FOR>\n");		int parntOutcomes = 1;		if(n.prnts!=null)		    for(int pidx=0; pidx<n.prnts.length; pidx++) {			GraphNode prnt = (GraphNode)nodes.elementAt(n.prnts[pidx]);			text.append("\t<GIVEN>" + XMLNormalize(prnt.ID) + "</GIVEN>\n");			if(prnt.outcomes!=null)			    parntOutcomes *= prnt.outcomes.length;		    }		text.append("<TABLE>\n");		for(int i=0; i<parntOutcomes; i++) {		    if(n.outcomes!=null)			for(int outidx=0; outidx<n.outcomes.length; outidx++){			    text.append(n.probs[i][outidx]+" ");			}		    else			text.append("1");		    text.append('\n');		}		text.append("</TABLE>\n");		text.append("</DEFINITION>\n");	    }	    text.append("</NETWORK>\n");	    text.append("</BIF>\n");		    outfile.write(text.toString());	    outfile.close();	}	catch(IOException ex) { ex.printStackTrace(); }    } // writeXMLBIF