Document doc = docBuilder.parse(new InputSource(new StringReader(wsdl)));
'wsdl' is the string I'm trying to parse. I have no experience at all in Java programming and I've been stuck on this for ages. Does anyone have a clue?
Thanks in advance!
Siten0308 - Jun 20 2019 01:43 PM
johnnylo - Apr 23 2019 07:49 AM
PJohnson - Apr 18 2019 03:55 AM
xarzu - Apr 05 2019 09:17 AM
xarzu - Apr 04 2019 11:47 AM
Posted 27 July 2012 - 10:13 AM
Document doc = docBuilder.parse(new InputSource(new StringReader(wsdl)));
Posted 28 July 2012 - 01:32 PM
Posted 28 July 2012 - 02:29 PM
<% String wsdl = request.getParameter("wsdl"); try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); DocumentBuilder docBuilder = dbf.newDocumentBuilder(); Document doc = docBuilder.parse(new InputSource(new StringReader(wsdl))); /* This is where it stops */ NamespaceContext ctx = new NamespaceContext() { public String getNamespaceURI(String prefix) { String uri; if (prefix.equals("sml")) uri = "http://www.opengis.net/sos/1.0"; else if (prefix.equals("gml")) uri = "http://www.opengis.net/sos/1.0"; else if (prefix.equals("swe")) uri = "http://www.opengis.net/sos/1.0"; else uri = null; return uri; } public Iterator<int[]> getPrefixes(String val) { return null; } public String getPrefix(String uri) { return null; } }; XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); xpath.setNamespaceContext(ctx); XPathExpression expr = xpath.compile("//sml:SensorML/*/sml:value"); Object result = expr.evaluate(doc, XPathConstants.NODESET); NodeList nodes = (NodeList) result; int len = nodes.getLength(); for (int i = 0; i < len; i++) { out.print(nodes.item(i).getNodeValue()); } } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { /* This is the exception I get */ e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (XPathExpressionException e) { e.printStackTrace(); } %>
Posted 28 July 2012 - 02:37 PM
Posted 28 July 2012 - 02:56 PM
import org.w3c.dom.NodeList; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathFactory; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathException; import java.io.IOException; import org.xml.sax.SAXException; import javax.xml.parsers.ParserConfigurationException; import java.util.Iterator; import javax.xml.namespace.NamespaceContext; import java.io.StringReader; import org.xml.sax.InputSource; import org.w3c.dom.Document; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; public class test { public static void main (String args[]) { String wsdl = "<sml:SensorML version='1.0.1' xsi:schemaLocation='http://www.opengis.net/sensorML/1.0.1 http://schemas.opengis.net/sensorML/1.0.1/sensorML.xsd'><sml:member><sml:System><!--sml:identification element must contain the ID of the sensor--><sml:identification><sml:IdentifierList><sml:identifier><sml:Term definition='urn:ogc:def:identifier:OGC:uniqueID'><sml:value>" + "urn:ogc:object:feature:Sensor:IFGI:ifgi-sensor-1" + "</sml:value></sml:Term></sml:identifier></sml:IdentifierList></sml:identification><!-- sml:capabilities element has to contain status and mobility information --><sml:capabilities><swe:SimpleDataRecord><!-- status indicates, whether sensor is collecting data at the moment (true) or not (false) --><swe:field name='status'><swe:Boolean><swe:value>true</swe:value></swe:Boolean></swe:field><!-- status indicates, whether sensor is mobile (true) or fixed (false) --><swe:field name='mobile'><swe:Boolean><swe:value>false</swe:value></swe:Boolean></swe:field></swe:SimpleDataRecord></sml:capabilities><!-- last measured position of sensor --><sml:position name='sensorPosition'><swe:Position referenceFrame='urn:ogc:def:crs:EPSG::4326'><swe:location><swe:Vector gml:id='STATION_LOCATION'><swe:coordinate name='easting'><swe:Quantity axisID='x'><swe:uom code='degree'/><swe:value>7.727958</swe:value></swe:Quantity></swe:coordinate><swe:coordinate name='northing'><swe:Quantity axisID='y'><swe:uom code='degree'/><swe:value>51.883906</swe:value></swe:Quantity></swe:coordinate><swe:coordinate name='altitude'><swe:Quantity axisID='z'><swe:uom code='m'/><swe:value>52.0</swe:value></swe:Quantity></swe:coordinate></swe:Vector></swe:location></swe:Position></sml:position><!-- list containing the input phenomena for this sensor system --><sml:inputs><sml:InputList><sml:input name='waterlevel'><swe:ObservableProperty definition='urn:ogc:def:phenomenon:OGC:1.0.30:waterlevel'/></sml:input></sml:InputList></sml:inputs><!-- list containing the output phenomena of this sensor system; ATTENTION: these phenomena are parsed and inserted into the database; they have to contain offering elements to determine the correct offering for the sensors and measured phenomena --><sml:outputs><sml:OutputList><sml:output name='waterlevel'><swe:Quantity definition='urn:ogc:def:phenomenon:OGC:1.0.30:waterlevel'><gml:metaDataProperty><offering><id>GAUGE_HEIGHT</id><name>" + "waterlevel of rivers in North" + "Rhine Westfalia" + "</name></offering></gml:metaDataProperty><swe:uom code='cm'/></swe:Quantity></sml:output></sml:OutputList></sml:outputs><!-- description of components of this sensor system; these are currently not used by the 52N SOS --><sml:components><sml:ComponentList><sml:component name='water sensor'><sml:Component><sml:identification><sml:IdentifierList><sml:identifier><sml:Term definition='urn:ogc:def:identifier:OGC:uniqueID'><sml:value>" + "urn:ogc:object:feature:Sensor:water_level_sensor" + "</sml:value></sml:Term></sml:identifier></sml:IdentifierList></sml:identification><sml:inputs><sml:InputList><sml:input name='waterlevel'><swe:ObservableProperty definition='urn:ogc:def:phenomenon:OGC:1.0.30:waterlevel'/></sml:input></sml:InputList></sml:inputs><sml:outputs><sml:OutputList><sml:output name='waterlevel'><swe:Quantity definition='urn:ogc:def:phenomenon:OGC:1.0.30:waterlevel'><swe:uom code='cm'/></swe:Quantity></sml:output></sml:OutputList></sml:outputs></sml:Component></sml:component></sml:ComponentList></sml:components></sml:System></sml:member></sml:SensorML>"; try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); DocumentBuilder docBuilder = dbf.newDocumentBuilder(); Document doc = docBuilder.parse(new InputSource(new StringReader(wsdl))); NamespaceContext ctx = new NamespaceContext() { public String getNamespaceURI(String prefix) { String uri; if (prefix.equals("sml")) uri = "http://www.opengis.net/sos/1.0"; else if (prefix.equals("gml")) uri = "http://www.opengis.net/sos/1.0"; else if (prefix.equals("swe")) uri = "http://www.opengis.net/sos/1.0"; else uri = null; return uri; } public Iterator<int[]> getPrefixes(String val) { return null; } public String getPrefix(String uri) { return null; } }; XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); xpath.setNamespaceContext(ctx); XPathExpression expr = xpath.compile("//sml:SensorML/*/sml:value"); Object result = expr.evaluate(doc, XPathConstants.NODESET); NodeList nodes = (NodeList) result; int len = nodes.getLength(); for (int i = 0; i < len; i++) { System.out.print(nodes.item(i).getNodeValue()); } } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (XPathExpressionException e) { e.printStackTrace(); } System.exit(0); } }
Posted 28 July 2012 - 03:08 PM
Posted 29 July 2012 - 02:07 AM
xmlns:sml="http://www.opengis.net/sensorML/1.0.1" xsi:schemaLocation="http://www.opengis.net/sensorML/1.0.1 http://schemas.opengis.net/sensorML/1.0.1/sensorML.xsd"this should be in the root tag, And you seem to be missing the first line of this.
Posted 10 August 2012 - 09:48 AM
www.pickmike.com
I don't just develop software. I find solutions to your business needs.
Language Forums →
C and C++ →
Why is similar string comparison giving different result?Started by nick112, 29 May 2017 ![]() |
|
![]() |
||
Language Forums →
C and C++ →
converting string to floatStarted by JonElias, 14 May 2016 ![]() |
|
![]() |
||
Language Forums →
HTML, CSS and Javascript →
How to find location of all the times a specific letter appears in stringStarted by 4ringsa6, 02 Mar 2016 ![]() |
|
![]() |
||
Language Forums →
Java →
How do I remove a character from a String?Started by dreddooo, 01 Oct 2015 ![]() |
|
![]() |
||
Language Forums →
Java →
Help needed making a String, which has all the letters in the rack (Scrabble game)Started by BobbyRedSox28, 25 May 2015 ![]() |
|
![]() |