import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class CommonSettingsXmlDAO
{
private CommonSettingsXmlDAO()
{
} public static Map loadCommonSettings(String location)
throws IOException
{
if(location != null && !location.equals(""))
{
return CommonSettingsXmlDAO.getParamMappings(location);
}
else
{
}
}
private static Map getParamMappings(String url)
throws IOException
{
HashMap paramMapping = new HashMap(); ConfigUtilities configUtilities = new ConfigUtilities();
Document doc = configUtilities.parse(url , true); if(doc != null)
{
configUtilities.setDocument(doc);
ArrayList nodes = configUtilities.findNodes("con/mapping"); Node node = null;
//遍历所有的<mappings>节点
for(int i = 0 ; i < nodes.size() ; i++)
{
node = (Node)nodes.get(i);
String paramName = getSubTagValue(node, "param-name");
String paramValue = getSubTagValue(node, "param-value");
//System.out.println("paramName = " + paramName);
//System.out.println("paramValue = " + paramValue);
if(paramName != null && paramValue != null)
{
paramMapping.put(paramName.trim() , paramValue.trim());
}
} return paramMapping;
}
else
{
}
} private static String getSubTagValue(Node node, String subTagName)
{
String returnString = ""; if (node != null && subTagName != null)
{
NodeList children = node.getChildNodes(); for (int innerLoop =0; innerLoop < children.getLength(); innerLoop++)
{
Node child = children.item(innerLoop); if ((child != null)
&& (child.getNodeName() != null)
&& child.getNodeName().equals(subTagName))
{
//获取文本节点
Node grandChild = child.getFirstChild();
if (grandChild.getNodeValue() != null)
{
return grandChild.getNodeValue();
}
}
} // end inner loop
} return returnString;
} public static void main(String[] args)
{
try
{
CommonSettingsXmlDAO.loadCommonSettings("E:/yy.xml");
}
catch (IOException ex)
{
ex.printStackTrace();
}
}}
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class CommonSettingsXmlDAO
{
private CommonSettingsXmlDAO()
{
} public static Map loadCommonSettings(String location)
throws IOException
{
if(location != null && !location.equals(""))
{
return CommonSettingsXmlDAO.getParamMappings(location);
}
else
{
}
}
private static Map getParamMappings(String url)
throws IOException
{
HashMap paramMapping = new HashMap(); ConfigUtilities configUtilities = new ConfigUtilities();
Document doc = configUtilities.parse(url , true); if(doc != null)
{
configUtilities.setDocument(doc);
ArrayList nodes = configUtilities.findNodes("con/mapping"); Node node = null;
//遍历所有的<mappings>节点
for(int i = 0 ; i < nodes.size() ; i++)
{
node = (Node)nodes.get(i);
String paramName = getSubTagValue(node, "param-name");
String paramValue = getSubTagValue(node, "param-value");
//System.out.println("paramName = " + paramName);
//System.out.println("paramValue = " + paramValue);
if(paramName != null && paramValue != null)
{
paramMapping.put(paramName.trim() , paramValue.trim());
}
} return paramMapping;
}
else
{
}
} private static String getSubTagValue(Node node, String subTagName)
{
String returnString = ""; if (node != null && subTagName != null)
{
NodeList children = node.getChildNodes(); for (int innerLoop =0; innerLoop < children.getLength(); innerLoop++)
{
Node child = children.item(innerLoop); if ((child != null)
&& (child.getNodeName() != null)
&& child.getNodeName().equals(subTagName))
{
//获取文本节点
Node grandChild = child.getFirstChild();
if (grandChild.getNodeValue() != null)
{
return grandChild.getNodeValue();
}
}
} // end inner loop
} return returnString;
} public static void main(String[] args)
{
try
{
CommonSettingsXmlDAO.loadCommonSettings("E:/yy.xml");
}
catch (IOException ex)
{
ex.printStackTrace();
}
}}
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
这几个包从哪里来?
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.*;
import java.io.*;public class SelectStud { public static void main(String[] args) {
String headerstring="<?xml version=\"1.0\"?>";
String root="<students>";
String rootend="</students>";
try{
File ff=new File("students.xml");
ff.createNewFile();
FileWriter fw=new FileWriter(ff);
fw.write(headerstring);
fw.write(root);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:oradsn","wanchao","oracle");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from students");
while(rs.next()){
fw.write("<student>");
fw.write("<stud_id>");
String stud_id=rs.getString("stud_id");
fw.write(stud_id);
fw.write("</stud_id>");
fw.write("<stud_name>");
String stud_name=rs.getString("stud_name");
fw.write("stud_name");
fw.write("</stud_name>");
fw.write("</student>");
}
fw.write(rootend);
fw.close();
}
catch(Exception e){
System.out.println(e);
}
}
}
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;
public XMLParser() {
super();
}
public static String output(Document doc) throws Exception{
XMLOutputter output=new XMLOutputter(); return output.outputString(doc);
}
public static String output(Element element) throws Exception{
XMLOutputter output=new XMLOutputter(); return output.outputString(element);
}
public static Document parse(String strXML) throws Exception{
SAXBuilder sax=new SAXBuilder();
return sax.build(new StringReader(strXML));
}
}
DECLARE @idoc int
DECLARE @doc varchar(1000)
--sample XML document
SET @doc ='
<root>
<Customer cid= "C1" name="Janine" city="Issaquah">
<Order oid="O1" date="1/20/1996" amount="3.5" />
<Order oid="O2" date="4/30/1997" amount="13.4">Customer was very satisfied
</Order>
</Customer>
<Customer cid="C2" name="Ursula" city="Oelde" >
<Order oid="O3" date="7/14/1999" amount="100" note="Wrap it blue
white red">
<Urgency>Important</Urgency>
Happy Customer.
</Order>
<Order oid="O4" date="1/20/1996" amount="10000"/>
</Customer>
</root>
'
-- Create an internal representation of the XML document.
EXEC sp_xml_preparedocument @idoc OUTPUT, @doc-- Execute a SELECT statement using OPENXML rowset provider.
SELECT *
FROM OPENXML (@idoc, '/root/Customer/Order', 1)
WITH (oid char(5),
amount float,
comment ntext 'text()')
EXEC sp_xml_removedocument @idoc