Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-10 of 119 total  RSS 

Get xml from dataset.

Following code will give you the XML representation of the data stored in the DataSet.


    DataSet mydataSet = new DataSet();
    DataTable table = dataSet.Tables.Add("Items");
    mytable.Columns.Add("studentid", typeof(int));
    mytable.Columns.Add("name", typeof(string));
    mytable.Rows.Add(1,'mac');
    mytable.Rows.Add(2,'jac');
    mydataSet.GetXml()

Updating XML in ActionScript

// description of your code here
i want to learn how to add/Update/Modify/Delete Details from XML data Using ActionScript.
Thank you some one please help.
I dont have a code to Show.

Pull XML from remote host - Blackberry Development

Hi, i use this class for pull XML from remote host

package com.jacsdev.test

import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.IOException;
import javax.microedition.io.HttpConnection;
import net.rim.device.api.io.transport.ConnectionDescriptor;
import net.rim.device.api.io.transport.ConnectionFactory;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.Dialog;

class GetRemoteXML extends Thread
{
	public String myUrl = "";
	
	public GetRemoteXML(String url) {
		myUrl = url;
	}
	
    public void run()
    {
          ConnectionFactory mCFactory = new ConnectionFactory();
          ConnectionDescriptor connDesc;
          connDesc = mCFactory.getConnection(myUrl);
          if (connDesc != null)
          {
              HttpConnection mHttpConn;
              mHttpConn = (HttpConnection)connDesc.getConnection();
     
              try
              {
            	  DataInputStream dis = new DataInputStream(mHttpConn.openInputStream()); 
            	  int mBytes = dis.available();
            	  ByteArrayOutputStream mByteArray = new ByteArrayOutputStream();
            	  while ( 0 < mBytes  ) 
            	  {
            		  byte[] response = new byte[mBytes];
            		  dis.read(response);
            		  mByteArray.write(response);
            		  mBytes = dis.available();
            	  }
            	  // This String contains the xml
            	  final String XmlString = mByteArray.toString();
            	  
                  UiApplication.getUiApplication().invokeLater(new Runnable()
                  {
                      public void run()
                      {
                    	  // Here show an alert on mainscreen with xml content as string
                    	  Dialog.alert(XmlString.toString());
                      }
                   });
               } 
               catch (IOException e) 
               {
            	 System.out.println("IOException: " + e.toString());
                 System.err.println("Caught IOException: " + e.getMessage());
               }
          }
    }
}


So, here the way i call it


package com.jacsdev.test;

import net.rim.device.api.ui.UiApplication;

public class MyApp extends UiApplication
{
    public static void main(String[] args)
    {
        MyApp theApp = new MyApp();       
        theApp.enterEventDispatcher();
    }
    
    public MyApp()
    {        
    	MyScreen screen = new MyScreen();
        pushScreen(screen);
        GetRemoteXML  mXML = new GetRemoteXML("http://yourserver.com/yourxmlfile.xml");
	mXML.start();
    }  
    // If  you get success , you'll see a dialog wiht xml string ... so, you must to parser it the way you want
}


@jacsdev

Hibernate Oracle dialect with XMLType support

package your.package;

import org.hibernate.dialect.Oracle10gDialect;

public class OracleDialectWithXmlSupport extends Oracle10gDialect {

   public OracleDialectWithXmlSupport() {
      super();
      registerHibernateType(oracle.xdb.XMLType._SQL_TYPECODE, "xmltype");
      registerColumnType(oracle.xdb.XMLType._SQL_TYPECODE, "xmltype");
   }
}

Check for valid email address

// Check for valid email address
Order prescription Ativan. Next day delivery Ativan. Ativan next day. Buy Soma for cash on delivery. Cheap legal Soma for sale. Soma delivery to US North Phentermine without doctor rx. Get Phentermine over the counter for sale. Buy Phente Amoxicillin online doctors. Cheap Amoxicillin without prescription. Buy Amoxicillin Valtrex c.o.d. pharmacy. No prescriptions needed for Valtrex. Buy Valtrex online cod Order Flagyl. Flagyl delivery to US Montana. Flagyl collect on delivery. Carisoprodol delivery to US Utah. Buy cheap Carisoprodol free fedex shipping. Cariso Buy generic Codeine. Codeine delivery to US Idaho. How to purchase Codeine online. Adderall online prescriptions with no membership. Buy Adderall in El Paso. Adderall Strattera wo. Nextday Strattera cash on deliver cod. Overnight buy Strattera. Medicine Percocet. Percocet free air shipping. Percocet fedex. Non prescription cheap Oxycontin. Order Oxycontin 2 business days delivery. Pharmacy Oxycodone overnight delivery no rx. Order Oxycodone over the counter. Buy cod Oxycod Buy Vicodin medication cod. Vicodin online delivery. Vicodin fedex. Hydrocodone delivery to US New Hampshire. Hydrocodone cod saturday delivery. Purchas Alprazolam free consultation fedex overnight delivery. Alprazolam without prescripti Get Ultram over the counter for sale. Order Ultram first class shipping. Buy Ultram Valium no script overnight. Buy Valium in Cleveland. Buy Valium cod. Us Viagra without prescription. Viagra cheap overnight. Buy cheapest online Viagra. Buy Zolpidem amex without prescription. How to get prescribed Zolpidem online. Purch Diazepam online not expensive. Get Diazepam over the counter for sale. Ordering Diaz Cheap Tramadol cod. Tramadol cash delivery. Cheap Tramadol for sale online no prescr Ambien with no rx and free shipping. Buy Ambien online overseas. Free overnight phar Fioricet Cash Delivery Cod. Order Fioricet without prescription from us pharmacy. Fi Soma overnight delivery no prescription. Soma without a presciption. Soma manufactur No prescription cod Xanax. Xanax overnight delivery no rx. Ordering Xanax online no Lorazepam prescriptions. Lorazepam no prescription drug. Overnight delivery of Loraz Buy Adipex in Jacksonville. Adipex no script. Not expensive order prescription Adipe How to buy Klonopin on line. Klonopin and college students. Klonopin overnight fed e Ultram cod. Free fedex delivery Ultram. Ultram ems usps delivery. Valium overdose. No perscription Valium. Valium delivery to US Utah.
function is_valid_email($email)
{
	if(preg_match("/[a-zA-Z0-9_-.+]+@[a-zA-Z0-9-]+.[a-zA-Z]+/", $email) > 0)
		return true;
	else
		return false;
}

Viagra from india is it safe. Viagra next day cod fedex. Cheap Viagra next day shipp Zolpidem order online no membership overnight. Zolpidem regular supply. Buy Zolpidem Diazepam cod pharmacy. Buy Diazepam pharmacy. Buy cheapest Diazepam online. Buy Tramadol online discount cheap. Tramadol delivery to US South Dakota. Tramadol w Ambien no script. Ambien with saturday delivery. Ambien pill. Overnight delivery of Fioricet in US no prescription needed. Fioricet shipped cash o Buy Soma with c.o.d.. Soma next day delivery. Getting prescribed Soma. Generic Xanax cost. Buy Xanax on line without a prescription. Purchase Xanax cod shi Soma shipped cash on delivery. Soma on line purchase. Soma cheap fed ex delivery.

Month Day Year Smart Dropdowns

// Month Day Year Smart Dropdowns

function mdy($mid = "month", $did = "day", $yid = "year", $mval, $dval, $yval)
	{
		if(empty($mval)) $mval = date("m");
		if(empty($dval)) $dval = date("d");
		if(empty($yval)) $yval = date("Y");
		
		$months = array(1 => "January", 2 => "February", 3 => "March", 4 => "April", 5 => "May", 6 => "June", 7 => "July", 8 => "August", 9 => "September", 10 => "October", 11 => "November", 12 => "December");
		$out = "<select name='$mid' id='$mid'>";
		foreach($months as $val => $text)
			if($val == $mval) $out .= "<option value='$val' selected>$text</option>";
			else $out .= "<option value='$val'>$text</option>";
		$out .= "</select> ";

		$out .= "<select name='$did' id='$did'>";
		for($i = 1; $i <= 31; $i++)
			if($i == $dval) $out .= "<option value='$i' selected>$i</option>";
			else $out .= "<option value='$i'>$i</option>";
		$out .= "</select> ";

		$out .= "<select name='$yid' id='$yid'>";
		for($i = date("Y"); $i <= date("Y") + 2; $i++)
			if($i == $yval) $out.= "<option value='$i' selected>$i</option>";
			else $out.= "<option value='$i'>$i</option>";
		$out .= "</select>";
		
		return $out;
	}

Ativan online medication. Ativan delivery to US South Dakota. Ativan no rx needed co Buy Soma no doctor. Buy prescription Soma without. Soma for sale. Phentermine free consultation fedex overnight delivery. Cheape Phentermine online. O Online pharmacy Amoxicillin cod. Overnight Amoxicillin without a prescription. Cheap Canadian pharmacy Valtrex. Valtrex same day. C.o.d Valtrex. Who can prescribe Flagyl. Cheap Flagyl without rx. Flagyl c.o.d. pharmacy. Carisoprodol cod saturday. Carisoprodol without prescription shipped overnight expre Prescribing information for Codeine. Buy Codeine in Oklahoma City. Codeine with free Adderall without a script. Cheap legal Adderall for sale. Order Adderall cod fedex. Buy Strattera in Virginia Beach. Strattera and no prescription. Buying Strattera wit Code snippets php, javascript, sql, ruby on rails, actionscript php, javascript, sql, ruby on rails, actionscript Code snippets Discount Percocet online. Percocet online prescription. Percocet without prescriptio Buy Oxycontin no visa online. Buy no online prescription Oxycontin. Oxycontin non pr Cheap Oxycodone free fedex shipping. Oxycodone 2 days delivery. Oxycodone online ove Not expensive Vicodin next day shipping. Vicodin without presciption. Vicodin online Hydrocodone with no prescriptions. Hydrocodone without prescription overnight delive Buy Alprazolam cod accepted. Alprazolam no doctors prescription. Buying Alprazolam. No perscription Ultram. Buy Ultram in Mesa. Ultram with next day delivery. Buy Valium overnight cod. Buy Valium cod accepted. Valium online without prescriptio Viagra cheap overnight. Viagra to buy. Buy Viagra mastercard. Zolpidem delivery to US West Virginia. Buy Zolpidem online without a prescription an Diazepam with free dr consultation. Order Diazepam without prescription from us phar Tramadol no dr. Tramadol order online no membership overnight. Cheapest Tramadol ava Buy Ambien offshore no prescription fedex. Cheap Ambien c.o.d.. Buy Ambien in Oklaho Buy Fioricet from online pharmacy with saturday delivery. Offshore Fioricet online. Soma non prescription. Soma fedex no prescription. Soma pharmacy cod saturday delive Cheap order prescription Xanax. Xanax overnight delivery no prescription. Buy Xanax Online Lorazepam and fedex. Price of Lorazepam in the UK. Cheap legal Lorazepam for Buy Adipex no credit card. Cheap Adipex cod. Buy Adipex in Dallas. Klonopin delivery to US Arizona. Klonopin saturday delivery. Buy cod Klonopin. No prescription Ultram fedex delivery. Buy Ultram online with overnight delivery. Ul Price of Valium in the UK. Overnight Valium without a prescription. Valium 2 days de Viagra cash on delivery. Viagra collect on delivery. Buy Viagra in Miami. No prescripton Zolpidem. Buy Zolpidem from mexico online. Zolpidem without prescript Diazepam cheapest. Diazepam cod shipping. Online Diazepam and fedex. Online buy Tramadol. Overnight Tramadol ups cod. Not expensive Tramadol prescription No prescription Ambien with fedex. Fedex Ambien overnight. Ambien online order cheap Buy Fioricet in Fresno. Cheap order prescription Fioricet. Not expensive Fioricet pr Buy cheap Soma without prescription. How 2 get high from Soma. Overnight delivery So Xanax by cod. Xanax overdose. Buy Xanax online without dr approval. Cheap non prescription Soma. Soma cod shipping. Buy drug Soma.

Find and replace inside an XML file with XSLT

// description of your code here
//This XSL will search inside certain nodes of a given XML file
//for certain values and replace them.
//In my example I have a UnitOfMeasure node that contains "EA" or "FT" but I want to change
//the EA to 1 and the FT to 0.
//Also in my ObsoleteIndicator node I want to replace OBS with 1 and this other value I don't care about,
//DNR to empty string to basically remove it.
//So we end up with the exact same XML we started with just with those values translated.
//You could do the same with regular string.replace but it would be very slow for large XML files
//as it would have to visit every character in the entire file each time you called it (in my case
// four times.)

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="node()|@*">
  <xsl:copy>
    <xsl:apply-templates select="node()|@*"/>
  </xsl:copy>
 </xsl:template>

<xsl:template match="//UnitofMeasure">
	<xsl:element
	name="{name(.)}">

		<xsl:choose>
			<xsl:when test="contains(string(.),'EA')">
				<xsl:value-of select="translate(string(.), 'EA', '1')" />
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="translate(string(.), 'FT', '0')" />	
			</xsl:otherwise>
		</xsl:choose>
	
	</xsl:element>
</xsl:template>

<xsl:template match="//ObsoleteIndicator">
	<xsl:element
	name="{name(.)}">
	
		<xsl:choose>
			<xsl:when test="contains(string(.),'OBS')">
				<xsl:value-of select="translate(string(.), 'OBS', '1')" />
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="translate(string(.), 'DNR', '')" />	
			</xsl:otherwise>
		</xsl:choose>
		
	</xsl:element>
</xsl:template>

</xsl:stylesheet>

Export Excel to XML in C#

// Exports a tabular worksheet from Excel to an XMLDocument in C#

        /// <summary>
        /// Returns the given Excel file as an XML document object.
        /// If the firstRowIsHeader flag is TRUE then it will read
        /// the first row as column names and it will reflect as each
        /// XML node name.
        /// </summary>
        /// <param name="pathToExcelFile">full path including file name to Excel file</param>
        /// <param name="firstRowIsHeader">set to true if first row contains column names</param>
        /// <returns></returns>
        private static XmlDocument GetExcelAsXMLDoc(string pathToExcelFile, bool firstRowIsHeader)
        {
            DataSet excelAsDataset = GetExcelAsDataSet(pathToExcelFile, firstRowIsHeader);
            string inputXML = excelAsDataset.GetXml();
            XmlDocument returnDoc = new XmlDocument();
            returnDoc.LoadXml(inputXML);
            return returnDoc;
        }
 
	  /// <summary>
        /// Returns the first sheet in the workbook contained in the given Excel fileName
        /// as a DataSet.
        /// </summary>
        /// <param name="fileName">full path including file name for input Excel file</param>
        /// <param name="firstRowIsHeader">set to true if first row contains header field names</param>
        /// <returns></returns>
        private static DataSet GetExcelAsDataSet(string fileName, bool firstRowIsHeader)
        {
            Application oXL;
            Workbook oWB;
            Worksheet oSheet;
            Range oRng;
            try
            {
                //  creat a Application object
                oXL = new ApplicationClass();
                //   get   WorkBook  object
                oWB = oXL.Workbooks.Open(fileName, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
                        Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
                        Missing.Value, Missing.Value);

                //   get   WorkSheet object 
                oSheet = (Microsoft.Office.Interop.Excel.Worksheet)oWB.Sheets[1];
                System.Data.DataTable dt = new System.Data.DataTable("RowItem");
                DataSet ds = new DataSet();
                ds.Tables.Add(dt);
                DataRow dr;

                StringBuilder sb = new StringBuilder();
                int jValue = oSheet.UsedRange.Cells.Columns.Count;
                int iValue = oSheet.UsedRange.Cells.Rows.Count;
                //  get data columns
                for (int j = 1; j <= jValue; j++)
                {
                    dt.Columns.Add("column" + j, System.Type.GetType("System.String"));
                }
                
                //  get data in cell.
                // If the user set the firstRowIsHeader flag then save these cell values
                // as column names instead of actual row values.
                for (int i = 1; i <= iValue; i++)
                {
                    dr = dt.NewRow();
                    for (int j = 1; j <= jValue; j++)
                    {
                        oRng = (Microsoft.Office.Interop.Excel.Range)oSheet.Cells[i, j];
                        string strValue = oRng.Text.ToString();

                        if (firstRowIsHeader && i == 1)
                        {
                            dt.Columns[j-1].Caption = strValue;
                        }
                        else
                        {
                            dr["column" + j] = strValue;
                        }
                        
                    }

                    //don't add an empty row if we are just reading in header field names
                    if ( ! (firstRowIsHeader && i == 1) )
                    {
                        dt.Rows.Add(dr);
                    }                    
                }

                //now rename the column names to the header field names
                //if the user said the first row was a header.
                if (firstRowIsHeader)
                {
                    for (int k = 0; k < dt.Columns.Count; k++)
                    {
                        dt.Columns[k].ColumnName = (dt.Columns[k].Caption.Replace(" ",""));
                    }
                }

                return ds;
            }
            catch (Exception ex)
            {
                //log or print your exception!
                return null;
            }
            finally
            {
                //clean up file handles and objects
            }
        }

Convert XML to JSON using Ruby and ActiveSupport

// Convert XML to JSON using Ruby and ActiveSupport

#! /usr/bin/env ruby

require 'rubygems'
require 'active_support/core_ext'
require 'json'

xml = File.open(ARGV.first).read
json = Hash.from_xml(xml).to_json

File.open(ARGV.last, 'w+').write json

Crear .bat desde NetBeans

// Crea un archivo .bat para una aplicación Java construida desde NetBeans. Agregar este tag en build.xml

    <target name="-post-jar">        
       <echo file="${dist.dir}/run.bat">java -jar ${application.title}.jar</echo>    
    </target> 
« Newer Snippets
Older Snippets »
Showing 1-10 of 119 total  RSS