Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package first.project;
- import java.util.ArrayList;
- import java.util.List;
- import org.w3c.dom.Document;
- import org.w3c.dom.Element;
- import org.w3c.dom.Node;
- import org.w3c.dom.NodeList;
- import android.content.Intent;
- import android.graphics.Typeface;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.AdapterView;
- import android.widget.AdapterView.OnItemClickListener;
- import android.widget.ArrayAdapter;
- import android.widget.ListView;
- import android.widget.TextView;
- import android.widget.Toast;
- public class forparse extends second{
- String xml;
- Boolean description=false,attcolor=false,attsize=false,attjacket=false,attnestedsuitsize=false,attjacketpantstyle=false,attfrontinseam=false,attwaist=false,attcolorsize=false,imtitle=false,imurl=false;
- Boolean attribute=false,attshirtsize=false,attpantsize=false,attshirtcolor=false,attpantcolor=false,attwaistinseam=false;
- Document doc;
- Element e,se;
- NodeList ncategories,nsubcat,n;
- Node fstNode;
- List<String> CategoryId=new ArrayList<String>();
- List<String> CategoryName=new ArrayList<String>();
- List<String> SubCatsId=new ArrayList<String>();
- List<String> SubCatId=new ArrayList<String>();
- List<String> SubCatsName=new ArrayList<String>();
- List<String> SubCatName=new ArrayList<String>();
- List<String> ProductsId=new ArrayList<String>();
- List<String> ProductsName=new ArrayList<String>();
- ListView lv_parse;
- TextView tv_product;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- // TODO Auto-generated method stub
- super.onCreate(savedInstanceState);
- setContentView(R.layout.parse);
- tv_product=(TextView)findViewById(R.id.tv_pro);
- Bundle extra=getIntent().getExtras();
- if(extra!=null){
- String temp=extra.getString("product");
- Typeface font=Typeface.createFromAsset(getAssets(), "fonts/TrajanPro-Regular.otf");
- tv_product.setTypeface(font);
- tv_product.setText(temp);
- }
- lv_parse=(ListView)findViewById(R.id.lv_parsexml);
- /*try {
- xml= Parser.getXML(getAssets().open("original.xml"));
- }catch (IOException e) {
- e.printStackTrace();
- }*/
- xml = Parser.getXMLstring("http://justlinen.nopcommerce.net/ProductXML.aspx");
- Toast.makeText(this,xml,Toast.LENGTH_LONG).show();
- doc = Parser.XMLfromString(xml);
- String starttag=doc.getFirstChild().getNodeName();
- ncategories = doc.getElementsByTagName(starttag);
- int f = 0,t=0;
- for(int i=0;i<ncategories.getLength();i++){
- e=(Element)ncategories.item(i);
- n=e.getElementsByTagName("Category");
- for(int c=0;c<n.getLength();c++){
- e=(Element)n.item(c);
- Node ns=e.getParentNode();
- String ne=ns.getNodeName();
- if(ne.equalsIgnoreCase("Categories")){
- CategoryName.add(Parser.getValue(e, "Name"));
- CategoryId.add(Parser.getValue(e, "ID"));
- f++;
- }else if(ne.equalsIgnoreCase("SubCategories")){
- Node npa=ns.getParentNode();
- String np=ns.getParentNode().getNodeName();
- if(np.equalsIgnoreCase("Category")){
- String npar=npa.getParentNode().getNodeName();
- if(npar.equalsIgnoreCase("SubCategories")){
- SubCatId.add(Parser.getValue(e, "ID"));
- SubCatName.add(Parser.getValue(e, "Name"));
- }else if(npar.equalsIgnoreCase("Categories")){
- SubCatsId.add(Parser.getValue(e, "ID"));
- SubCatsName.add(Parser.getValue(e, "Name"));
- }
- }
- }
- }
- }
- ncategories = doc.getElementsByTagName("Product");
- for(int i=0;i<ncategories.getLength();i++){
- Element epro=(Element)ncategories.item(i);
- ProductsId.add(Parser.getValue(epro, "ID"));
- ProductsName.add(Parser.getValue(epro, "Name"));
- }
- lv_parse.setAdapter(new ArrayAdapter<String>(this,R.layout.raw,R.id.tv_parse,CategoryName));
- lv_parse.setTextFilterEnabled(true);
- lv_parse.setOnItemClickListener(new OnItemClickListener(){
- @Override
- public void onItemClick(AdapterView<?> arg0, View v, int position,
- long arg3) {
- // TODO Auto-generated method stub
- Parserxml Parse=new Parserxml();
- Parse.Documentparser(CategoryId.get(position),CategoryName.get(position));
- }
- });
- }
- public void OnClick(View v){
- switch(v.getId()){
- case R.id.iv_back:
- forparse.this.finish();
- break;
- }
- }
- public class Parserxml {
- public void Documentparser(String id, String name) {
- int flag=0;
- Intent in;
- NodeList nmainpro;
- Boolean Category=false,Subcats=false,Childcat=false,Products=false;
- List<String> Name = new ArrayList<String>();
- List<String> ID = new ArrayList<String>();
- List<String> Description=new ArrayList<String>();
- List<String> AttColor=new ArrayList<String>();
- List<String> AttSize=new ArrayList<String>();
- List<String> AttJacket=new ArrayList<String>();
- List<String> AttJacketPantStyle=new ArrayList<String>();
- List<String> AttWaist=new ArrayList<String>();
- List<String> AttFrontInSeam=new ArrayList<String>();
- List<String> AttNestedSuitSize=new ArrayList<String>();
- List<String> AttColorSize=new ArrayList<String>();
- List<String> AttWaistInSeam=new ArrayList<String>();
- List<String> AttShirtSize=new ArrayList<String>();
- List<String> AttPantSize=new ArrayList<String>();
- List<String> AttShirtColor=new ArrayList<String>();
- List<String> AttPantColor=new ArrayList<String>();
- List<String> ImTitle=new ArrayList<String>();
- List<String> ImURL=new ArrayList<String>();
- //////////////////////////////////////////////////////////////////////////////////////////////////
- for(int k=0;k<1;k++){
- for(int i=0;i<CategoryId.size();i++){
- if(CategoryId.get(i).equalsIgnoreCase(id)){
- Category=true;
- flag=1;
- break;
- }
- }
- if(flag==1){
- break;
- }
- for(int i=0;i<SubCatsId.size();i++){
- if(SubCatsId.get(i).equalsIgnoreCase(id)){
- Subcats=true;
- flag=1;
- break;
- }
- }
- if(flag==1){
- break;
- }
- for(int i=0;i<SubCatId.size();i++){
- if(SubCatId.get(i).equalsIgnoreCase(id)){
- Childcat=true;
- flag=1;
- break;
- }
- }
- if(flag==1){
- break;
- }
- for(int i=0;i<ProductsId.size();i++){
- if(ProductsId.get(i).equalsIgnoreCase(id)){
- Products=true;
- flag=1;
- break;
- }
- }
- if(flag==1){
- break;
- }
- }
- /////////////////////////////////////////////////////////////////////////////////////////////
- if(Category){
- // n=doc.getElementsByTagName("Category");
- int c=0;
- for(int i=0;i<n.getLength();i++){
- e=(Element)n.item(i);
- if(e.getParentNode().getNodeName().equalsIgnoreCase("Categories")){
- if(CategoryId.get(c).equalsIgnoreCase(id)){
- // for mainproducts
- nmainpro=e.getElementsByTagName("Products");
- for(int p=0;p<nmainpro.getLength();p++){
- Element emainproducts=(Element)nmainpro.item(p);
- Node npropar=emainproducts.getParentNode().getParentNode();
- if(npropar.getNodeName().equalsIgnoreCase("Categories")){
- NodeList nmainproduct=emainproducts.getElementsByTagName("Product");
- for(int m=0;m<nmainproduct.getLength();m++){
- Element emainproduct=(Element)nmainproduct.item(m);
- ID.add(Parser.getValue(emainproduct, "ID"));
- Name.add(Parser.getValue(emainproduct, "Name"));
- }
- }
- }
- //for subcategories
- nmainpro=e.getElementsByTagName("SubCategories");
- for(int p=0;p<nmainpro.getLength();p++){
- Element emainproducts=(Element)nmainpro.item(p);
- NodeList nmainproduct=emainproducts.getElementsByTagName("Category");
- for(int m=0;m<nmainproduct.getLength();m++){
- Element emainproduct=(Element)nmainproduct.item(m);
- if(emainproduct.getParentNode().getParentNode().getParentNode().getNodeName().equalsIgnoreCase("Categories")){
- ID.add(Parser.getValue(emainproduct, "ID"));
- Name.add(Parser.getValue(emainproduct, "Name"));
- }
- }
- }
- break;
- }
- c++;
- }
- }
- in=new Intent(forparse.this,SubCategories.class);
- in.putExtra("parent",name);
- in.putStringArrayListExtra("name",(ArrayList<String>) Name);
- in.putStringArrayListExtra("id",(ArrayList<String>) ID);
- startActivity(in);
- }else if(Subcats){
- // n=doc.getElementsByTagName("Category");
- for(int i=0;i<n.getLength();i++){
- e=(Element)n.item(i);
- String temp=Parser.getValue(e, "ID");
- if(temp.equalsIgnoreCase(id)){
- nmainpro=e.getElementsByTagName("Products");
- for(int p=0;p<nmainpro.getLength();p++){
- Element emainproduct=(Element)nmainpro.item(p);
- if(emainproduct.getParentNode().getParentNode().getParentNode().getParentNode().getNodeName().equalsIgnoreCase("Categories")){
- NodeList npro=emainproduct.getElementsByTagName("Product");
- for(int c=0;c<npro.getLength();c++){
- Element epro=(Element)npro.item(c);
- ID.add(Parser.getValue(epro, "ID"));
- Name.add(Parser.getValue(epro, "Name"));
- }
- }
- }
- nmainpro=e.getElementsByTagName("SubCategories");
- for(int p=0;p<nmainpro.getLength();p++){
- Element emainproduct=(Element)nmainpro.item(p);
- if(emainproduct.getParentNode().getParentNode().getParentNode().getParentNode().getNodeName().equalsIgnoreCase("Categories")){
- NodeList npro=emainproduct.getElementsByTagName("Category");
- for(int c=0;c<npro.getLength();c++){
- Element epro=(Element)npro.item(c);
- ID.add(Parser.getValue(epro, "ID"));
- Name.add(Parser.getValue(epro, "Name"));
- }
- }
- }
- break;
- }
- }
- in=new Intent(forparse.this,SubCategory.class);
- in.putExtra("parent",name);
- in.putStringArrayListExtra("name",(ArrayList<String>) Name);
- in.putStringArrayListExtra("id",(ArrayList<String>) ID);
- startActivity(in);
- }else if(Childcat){
- // n=doc.getElementsByTagName("Category");
- for(int i=0;i<n.getLength();i++){
- e=(Element)n.item(i);
- String temp=Parser.getValue(e, "ID");
- if(temp.equalsIgnoreCase(id)){
- nmainpro=e.getElementsByTagName("Products");
- for(int p=0;p<nmainpro.getLength();p++){
- Element emainproduct=(Element)nmainpro.item(p);
- if(emainproduct.getParentNode().getParentNode().getParentNode().getParentNode().getParentNode().getParentNode().getNodeName().equalsIgnoreCase("Categories")){
- NodeList npro=emainproduct.getElementsByTagName("Product");
- for(int c=0;c<npro.getLength();c++){
- Element epro=(Element)npro.item(c);
- ID.add(Parser.getValue(epro, "ID"));
- Name.add(Parser.getValue(epro, "Name"));
- }
- }
- }
- nmainpro=e.getElementsByTagName("SubCategories");
- for(int p=0;p<nmainpro.getLength();p++){
- Element emainproduct=(Element)nmainpro.item(p);
- if(emainproduct.getParentNode().getParentNode().getParentNode().getParentNode().getParentNode().getParentNode().getNodeName().equalsIgnoreCase("Categories")){
- NodeList npro=emainproduct.getElementsByTagName("Category");
- for(int c=0;c<npro.getLength();c++){
- Element epro=(Element)npro.item(c);
- ID.add(Parser.getValue(epro, "ID"));
- Name.add(Parser.getValue(epro, "Name"));
- }
- }
- }
- break;
- }
- }
- in=new Intent(forparse.this,ChildSubCategory.class);
- in.putExtra("parent",name);
- in.putStringArrayListExtra("name",(ArrayList<String>) Name);
- in.putStringArrayListExtra("id",(ArrayList<String>) ID);
- startActivity(in);
- }else if(Products){
- n=doc.getElementsByTagName("Product");
- for(int i=0;i<n.getLength();i++){
- Node fstnode=n.item(i);
- if(fstnode.getNodeType()==Node.ELEMENT_NODE){
- e=(Element)n.item(i);
- if(ProductsId.get(i).equalsIgnoreCase(id)){
- // for products detail
- ID.add(Parser.getValue(e, "ID"));
- Name.add(Parser.getValue(e, "Name"));
- Description.add(Parser.getValue(e, "Description"));
- for(int ate=0;ate<e.getChildNodes().getLength();ate++){
- Node natt=e.getChildNodes().item(ate);
- if(natt.getNodeName().equalsIgnoreCase("Attribute")){
- attribute=true;
- NodeList att=e.getElementsByTagName("Attribute");
- for(int a=0;a<att.getLength();a++){
- Element at=(Element)att.item(a);
- for(int atc=0;atc<at.getChildNodes().getLength();atc++){
- Node atnode=at.getChildNodes().item(atc);
- if(atnode.getNodeName().equalsIgnoreCase("Color")){
- attcolor=true;
- }
- if(atnode.getNodeName().equalsIgnoreCase("Size")){
- attsize=true;
- }
- if(atnode.getNodeName().equalsIgnoreCase("Jacket")){
- attjacket=true;
- }
- if(atnode.getNodeName().equalsIgnoreCase("JacketPantStyle")){
- attjacketpantstyle=true;
- }
- if(atnode.getNodeName().equalsIgnoreCase("NestedSuitSize")){
- attnestedsuitsize=true;
- }
- if(atnode.getNodeName().equalsIgnoreCase("ColorSize")){
- attcolorsize=true;
- }
- if(atnode.getNodeName().equalsIgnoreCase("Waist")){
- attwaist=true;
- }
- if(atnode.getNodeName().equalsIgnoreCase("FrontInseam")){
- attfrontinseam=true;
- }
- if(atnode.getNodeName().equalsIgnoreCase("ShirtSize")){
- attshirtsize=true;
- }
- if(atnode.getNodeName().equalsIgnoreCase("PantSize")){
- attpantsize=true;
- }
- if(atnode.getNodeName().equalsIgnoreCase("ShirtColor")){
- attshirtcolor=true;
- }
- if(atnode.getNodeName().equalsIgnoreCase("PantColor")){
- attpantcolor=true;
- }
- if(atnode.getNodeName().equalsIgnoreCase("WaistInseam")){
- attwaistinseam=true;
- }
- }
- NodeList nat;
- Element eat;
- if(attcolor){
- nat=at.getElementsByTagName("Color");
- for(int pat=0;pat<nat.getLength();pat++){
- eat=(Element)nat.item(pat);
- AttColor.add(Parser.getValue(eat, "Color"));
- }
- }
- if(attsize){
- nat=at.getElementsByTagName("Size");
- for(int pat=0;pat<nat.getLength();pat++){
- eat =(Element)nat.item(pat);
- AttSize.add(Parser.getValue(eat, "Size"));
- }
- }
- if(attjacket){
- nat=at.getElementsByTagName("Jacket");
- for(int pat=0;pat<nat.getLength();pat++){
- eat=(Element)nat.item(pat);
- AttJacket.add(Parser.getValue(eat, "Jacket"));
- }
- }
- if(attjacketpantstyle){
- nat=at.getElementsByTagName("JacketPantStyle");
- for(int pat=0;pat<nat.getLength();pat++){
- eat=(Element)nat.item(pat);
- AttJacketPantStyle.add(Parser.getValue(eat, "JacketPantStyle"));
- }
- }
- if(attnestedsuitsize){
- nat=at.getElementsByTagName("NestedSuitSize");
- for(int pat=0;pat<nat.getLength();pat++){
- eat=(Element)nat.item(pat);
- AttNestedSuitSize.add(Parser.getValue(eat, "NestedSuitSize"));
- }
- }
- if(attcolorsize){
- nat=at.getElementsByTagName("ColorSize");
- for(int pat=0;pat<nat.getLength();pat++){
- eat=(Element)nat.item(pat);
- AttColorSize.add(Parser.getValue(eat, "ColorSize"));
- }
- }
- if(attwaist){
- nat=at.getElementsByTagName("Waist");
- for(int pat=0;pat<nat.getLength();pat++){
- eat=(Element)nat.item(pat);
- AttWaist.add(Parser.getValue(eat, "Waist"));
- }
- }
- if(attfrontinseam){
- nat=at.getElementsByTagName("FrontInseam");
- for(int pat=0;pat<nat.getLength();pat++){
- eat=(Element)nat.item(pat);
- AttFrontInSeam.add(Parser.getValue(eat, "FrontInseam"));
- }
- }
- if(attshirtsize){
- nat=at.getElementsByTagName("ShirtSize");
- for(int pat=0;pat<nat.getLength();pat++){
- eat=(Element)nat.item(pat);
- AttShirtSize.add(Parser.getValue(eat, "ShirtSize"));
- }
- }
- if(attpantsize){
- nat=at.getElementsByTagName("PantSize");
- for(int pat=0;pat<nat.getLength();pat++){
- eat=(Element)nat.item(pat);
- AttPantSize.add(Parser.getValue(eat, "PantSize"));
- }
- }
- if(attshirtcolor){
- nat=at.getElementsByTagName("ShirtColor");
- for(int pat=0;pat<nat.getLength();pat++){
- eat=(Element)nat.item(pat);
- AttShirtColor.add(Parser.getValue(eat, "ShirtColor"));
- }
- }
- if(attpantcolor){
- nat=at.getElementsByTagName("PantColor");
- for(int pat=0;pat<nat.getLength();pat++){
- eat=(Element)nat.item(pat);
- AttPantColor.add(Parser.getValue(eat, "PantColor"));
- }
- }
- if(attwaistinseam){
- nat=at.getElementsByTagName("WaistInseam");
- for(int pat=0;pat<nat.getLength();pat++){
- eat=(Element)nat.item(pat);
- AttWaistInSeam.add(Parser.getValue(eat, "WaistInseam"));
- }
- }
- }
- }
- }
- NodeList im=e.getElementsByTagName("Images");
- for(int ima=0;ima<im.getLength();ima++){
- Element eim=(Element)im.item(ima);
- NodeList image=eim.getElementsByTagName("Image");
- for(int img=0;img<image.getLength();img++){
- Element eimg=(Element)image.item(img);
- ImTitle.add(Parser.getValue(eimg, "Title"));
- ImURL.add(Parser.getValue(eimg, "Url"));
- }
- }
- break;
- }
- }
- }
- in=new Intent(forparse.this,Product_Info.class);
- in.putStringArrayListExtra("Name",(ArrayList<String>) Name);
- in.putStringArrayListExtra("ID",(ArrayList<String>) ID);
- in.putStringArrayListExtra("Description",(ArrayList<String>) Description);
- if(attribute){
- in.putExtra("Attribute", attribute);
- attribute=false;
- if(attcolor){
- in.putExtra("Colors", true);
- in.putStringArrayListExtra("Color",(ArrayList<String>)AttColor);
- attcolor=false;
- }else{
- in.putExtra("Colors",false);
- }
- if(attsize){
- in.putExtra("Sizes", true);
- in.putStringArrayListExtra("Size",(ArrayList<String>)AttSize);
- attsize=false;
- }else{
- in.putExtra("Sizes", false);
- }
- if(attjacket){
- in.putExtra("Jackets", true);
- in.putStringArrayListExtra("Jacket",(ArrayList<String>) AttJacket);
- attjacket=false;
- }else{
- in.putExtra("Jackets",false);
- }
- if(attjacketpantstyle){
- in.putExtra("JacketPantStyles", true);
- in.putStringArrayListExtra("JacketPantStyle",(ArrayList<String>)AttJacketPantStyle);
- attjacketpantstyle=false;
- }else{
- in.putExtra("JacketPantStyles", false);
- }
- if(attnestedsuitsize){
- in.putExtra("NestedSuitSizes", true);
- in.putStringArrayListExtra("NestedSuitSize",(ArrayList<String>)AttNestedSuitSize);
- attnestedsuitsize=false;
- }else{
- in.putExtra("NestedSuitSizes",false);
- }
- if(attcolorsize){
- in.putExtra("ColorSizes", true);
- in.putStringArrayListExtra("ColorSize",(ArrayList<String>)AttColorSize);
- attcolorsize=false;
- }else{
- in.putExtra("ColorSizes", false);
- }
- if(attwaist){
- in.putExtra("Waists", true);
- in.putStringArrayListExtra("Waist",(ArrayList<String>)AttWaist);
- attwaist=false;
- }else{
- in.putExtra("Waists", false);
- }
- if(attfrontinseam){
- in.putExtra("FrontInSeams", true);
- in.putStringArrayListExtra("FrontInSeam",(ArrayList<String>)AttFrontInSeam);
- attfrontinseam=false;
- }else{
- in.putExtra("FrontInSeams", false);
- }
- if(attshirtsize){
- in.putExtra("ShirtSizes", true);
- in.putStringArrayListExtra("ShirtSize",(ArrayList<String>)AttShirtSize);
- attshirtsize=false;
- }else{
- in.putExtra("ShirtSizes", false);
- }
- if(attpantsize){
- in.putExtra("PantSizes", true);
- in.putStringArrayListExtra("PantSize",(ArrayList<String>)AttPantSize);
- attpantsize=false;
- }else{
- in.putExtra("PantSizes", false);
- }
- if(attshirtcolor){
- in.putExtra("ShirtColors", true);
- in.putStringArrayListExtra("ShirtColor",(ArrayList<String>)AttShirtColor);
- attshirtcolor=false;
- }else{
- in.putExtra("ShirtColors",false);
- }
- if(attpantcolor){
- in.putExtra("PantColors", true);
- in.putStringArrayListExtra("PantColor",(ArrayList<String>)AttPantColor);
- attpantcolor=false;
- }else{
- in.putExtra("PantColors",false);
- }
- if(attwaistinseam){
- in.putExtra("WaistInSeams", true);
- in.putStringArrayListExtra("WaistInSeam",(ArrayList<String>)AttWaistInSeam);
- attwaistinseam=false;
- }else{
- in.putExtra("WaistInSeams",false);
- }
- }else{
- in.putExtra("Attribute",attribute);
- }
- in.putStringArrayListExtra("Title",(ArrayList<String>)ImTitle);
- in.putStringArrayListExtra("Url",(ArrayList<String>)ImURL);
- startActivity(in);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment