-
Notifications
You must be signed in to change notification settings - Fork 2
/
xml.tries.txt
executable file
·157 lines (142 loc) · 4.51 KB
/
xml.tries.txt
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<FastQuoteResult xmlns="http://quote.cnbc.com/services/MultiQuote/2006">
<FastQuote>
<symbol>@GC.1</symbol>
<code>0</code>
<shortName>GOLD</shortName>
<last>1254.9</last>
<change>0.0</change>
<change_pct>0.0</change_pct>
<provider>CNBC Quote Cache</provider>
<cacheServed>false</cacheServed>
<cachedTime>Sun Jul 23 21:40:14 EDT 2017</cachedTime>
<responseTime>Sun Jul 23 21:40:14 EDT 2017</responseTime>
<realTime>false</realTime>
<quoteDesc/>
<source></source>
</FastQuote>
</FastQuoteResult>
// DocumentBuilder builder = null;
// DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// try
// {
// builder = factory.newDocumentBuilder();
// } catch (ParserConfigurationException e)
// {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
//
// StringBuilder xmlStringBuilder = new StringBuilder();
// Document doc = null;
// try
// {
// doc = builder.parse(new ByteArrayInputStream(response.toString().getBytes("UTF-8")));
// } catch (SAXException e)
// {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (IOException e)
// {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
//
// Element root = doc.getDocumentElement();
// NamedNodeMap nodeMap = doc.getAttributes();
// System.out.println("resulting xml is =" + response);
// parseXML(response.toString());
// DocumentBuilderFactory domFactory =
// DocumentBuilderFactory.newInstance();
// try {
// DocumentBuilder builder = domFactory.newDocumentBuilder();
// Document dDoc = builder.parse(response.toString());
//
// XPath xPath = XPathFactory.newInstance().newXPath();
// Node node = (Node) xPath.evaluate("/FastQuote/@symbol", dDoc,
// XPathConstants.NODE);
// System.out.println(node.getNodeValue());
// } catch (Exception e) {
// e.printStackTrace();
// }
// DocumentBuilderFactory factory =
// DocumentBuilderFactory.newInstance();
// DocumentBuilder builder = null;
// try
// {
// builder = factory.newDocumentBuilder();
// } catch (ParserConfigurationException e)
// {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// Document document = null;
// try
// {
// document = builder.parse(new InputSource(new
// StringReader(response.toString())));
// } catch (SAXException e)
// {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (IOException e)
// {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// Element rootElement = document.getDocumentElement();
// String result = "";
//
// NodeList list = rootElement.getElementsByTagName("FastQuote/@GC.1");
// if (list != null && list.getLength() > 0)
// {
// NodeList subList = list.item(0).getChildNodes();
//
// if (subList != null && subList.getLength() > 0)
// {
// result = subList.item(0).getNodeValue();
// }
// }
// private String parseXML(String input)
// {
// try
// {
//// File fXmlFile = new File("/Users/mkyong/staff.xml");
// DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
// DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
// Document doc = dBuilder.parse(input);
//
// // optional, but recommended
// // read this -
// // http://stackoverflow.com/questions/13786607/normalization-in-dom-parsing-with-java-how-does-it-work
// doc.getDocumentElement().normalize();
//
// System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
//
// NodeList nList = doc.getElementsByTagName("staff");
//
// System.out.println("----------------------------");
//
// for (int temp = 0; temp < nList.getLength(); temp++)
// {
//
// Node nNode = nList.item(temp);
//
// System.out.println("\nCurrent Element :" + nNode.getNodeName());
//
// if (nNode.getNodeType() == Node.ELEMENT_NODE)
// {
// Element eElement = (Element) nNode;
// System.out.println("Staff id : " + eElement.getAttribute("id"));
// System.out.println("First Name : " + eElement.getElementsByTagName("firstname").item(0).getTextContent());
// System.out.println("Last Name : " + eElement.getElementsByTagName("lastname").item(0).getTextContent());
// System.out.println("Nick Name : " + eElement.getElementsByTagName("nickname").item(0).getTextContent());
// System.out.println("Salary : " + eElement.getElementsByTagName("salary").item(0).getTextContent());
// }
// }
// } catch (Exception e)
// {
// e.printStackTrace();
// }
//
// return ("Hello");
// }