Clicky

Hello There,

This is a DOM java code, can anyone change it to PHP code ?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
import java.io.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;

public class DOMSearch
{
	public static void main(String args[])
	{
		if(args.length>1)
		{
			System.out.println("Please enter Series name!");
			
		}else
		{
			try
			{	
				DocumentBuilderFactory builderfactory=DocumentBuilderFactory.newInstance();
				DocumentBuilder builder=builderfactory.newDocumentBuilder();
				File file = new File("/public/courses/DocumentMarkupLanguages/A3_2010/TVGuide.xml");
				Document doc = builder.parse(file);
				NodeList serieses = doc.getElementsByTagName("Series");

				String seriesName=args[0], flag=null;
                                boolean seriesFound=false;
			
			
			for(int i=0; i<serieses.getLength(); i++)
			{				
					Element e=(Element)serieses.item(i);						
					if(e.hasChildNodes())
					{
						// if the entered series matchs any node, get the channel name and all its child nodes
						if(seriesName.equalsIgnoreCase(e.getFirstChild().getNodeValue()))
						{								
							seriesFound=true;
							Node parentChannel=e.getParentNode().getParentNode();
							NodeList childNodes=parentChannel.getChildNodes();							
							
							
							for(int j=0;j<childNodes.getLength();j++)
							{					
								// if the child node matchs "Name"		
								if(childNodes.item(j).getNodeType()==Node.ELEMENT_NODE && childNodes.item(j).getNodeName()=="Name")
								{
									
									String channelName=childNodes.item(j).getFirstChild().getNodeValue();																		
									// if the same channel has 2 start times for same series
									if(flag!=null && flag.equalsIgnoreCase(channelName)==true )
									{
									    Node duration=e.getPreviousSibling().getPreviousSibling();
										Node startTime=duration.getPreviousSibling().getPreviousSibling();
										System.out.println(startTime.getFirstChild().getNodeValue());
									}
								
									//if the channel has just 1 start time
									 if(flag==null)
                                      {
                                        flag=childNodes.item(j).getFirstChild().getNodeValue();
                                        Node duration=e.getPreviousSibling().getPreviousSibling();
                                        Node startTime=duration.getPreviousSibling().getPreviousSibling();
										System.out.println(channelName);
                                        System.out.println(startTime.getFirstChild().getNodeValue());
                                       }
										
									//if the series exists in different channel as well
									 if(flag.equalsIgnoreCase(channelName)==false)
										{
											flag=channelName;
											Node duration=e.getPreviousSibling().getPreviousSibling();
											Node startTime=duration.getPreviousSibling().getPreviousSibling();
											System.out.println(channelName);
											System.out.println(startTime.getFirstChild().getNodeValue());													
										}									
								}							
							}							
						}
					}					
				}				
				if(seriesFound==false)
				{
					System.out.println("Series '"+seriesName+"' not found.");
				}				
			}catch(Exception e)
				{					
					e.printStackTrace();					
				}			
		}		
	}
}

asked 10/04/2010 02:12

AussieSilver's gravatar image

AussieSilver ♦♦


4 Answers:
Thanks.

But i need someone to convert the existing code.
link
AussieSilver's gravatar image

AussieSilver

I am sorry, but i don't think we are allowed to write the whole code for you. Please make an attempt to write the code and let us know if you face any difficulty.

Moreover, i would suggest that this question should also go to the 'php' zone.

Also it would be better, if you can just write your requirement and post a question in PHP zone for getting more insights on this.
link
gurvinder372's gravatar image

gurvinder372

Your answer
[hide preview]

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

×1

Asked: 10/04/2010 02:12

Seen: 336 times

Last updated: 10/03/2010 11:50