Java Code Examples for com.sun.xml.xsom.parser.XSOMParser#getResult()
The following examples show how to use
com.sun.xml.xsom.parser.XSOMParser#getResult() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SoapProtocol.java From jolie with GNU Lesser General Public License v2.1 | 6 votes |
private XSSchemaSet getSchemaSet() throws IOException, SAXException { if( schemaSet == null ) { XSOMParser schemaParser = new XSOMParser(); ValueVector vec = getParameterVector( "schema" ); if( vec.size() > 0 ) { for( Value v : vec ) { schemaParser.parse( new File( v.strValue() ) ); } } parseWSDLTypes( schemaParser ); schemaSet = schemaParser.getResult(); String nsPrefix = "jolie"; int i = 1; for( XSSchema schema : schemaSet.getSchemas() ) { if( !schema.getTargetNamespace().equals( XMLConstants.W3C_XML_SCHEMA_NS_URI ) ) { namespacePrefixMap.put( schema.getTargetNamespace(), nsPrefix + i++ ); } } } return schemaSet; }
Example 2
Source File: SimpleTypesAnalyzerTest.java From hyperjaxb3 with BSD 2-Clause "Simplified" License | 5 votes |
public XSSchemaSet parse(String resource) throws Exception { final XSOMParser parser = new XSOMParser(); parser.setErrorHandler(null); parser.setEntityResolver(null); final URL resourceUrl = getClass().getClassLoader().getResource( resource); // parser.parseSchema( // // new File("myschema.xsd")); // parser.parseSchema( new File("XHTML.xsd")); parser.parse(resourceUrl); XSSchemaSet sset = parser.getResult(); return sset; }
Example 3
Source File: XmlUtils.java From jolie with GNU Lesser General Public License v2.1 | 4 votes |
public static void valueToDocument( Value value, Document document, String schemaFilename ) throws IOException { String rootName = value.children().keySet().iterator().next(); Value root = value.children().get( rootName ).get( 0 ); String rootNameSpace = ""; if( root.hasChildren( jolie.xml.XmlUtils.NAMESPACE_ATTRIBUTE_NAME ) ) { rootNameSpace = root.getFirstChild( jolie.xml.XmlUtils.NAMESPACE_ATTRIBUTE_NAME ).strValue(); } XSType type = null; if( schemaFilename != null ) { try { XSOMParser parser = new XSOMParser(); parser.parse( schemaFilename ); XSSchemaSet schemaSet = parser.getResult(); if( schemaSet != null && schemaSet.getElementDecl( rootNameSpace, rootName ) != null ) { type = schemaSet.getElementDecl( rootNameSpace, rootName ).getType(); } else if( schemaSet != null && schemaSet.getElementDecl( rootNameSpace, rootName ) == null ) { Interpreter.getInstance().logWarning( "Root element " + rootName + " with namespace " + rootNameSpace + " not found in the schema " + schemaFilename ); } } catch( SAXException e ) { throw new IOException( e ); } } if( type == null ) { valueToDocument( value.getFirstChild( rootName ), rootName, document ); } else { valueToDocument( value.getFirstChild( rootName ), rootName, document, type ); } }
Example 4
Source File: XMLSchemaProcessor.java From ET_Redux with Apache License 2.0 | 4 votes |
private XSSimpleType parse ( SchemaSimpleType schemaSimpleType ) { ClassLoader cldr = this.getClass().getClassLoader(); InputStream resourceXMLSchema = cldr.getResourceAsStream( schemaSimpleType.getSchemaFilePath() ); File localXMLSchema = new File( schemaSimpleType.getTypeName() + ".xsd" ); try { InputStream in = resourceXMLSchema; // Overwrite the file. OutputStream out = new FileOutputStream( localXMLSchema ); while (in.available() > 0) { byte[] buf = new byte[1024]; int len; while ((len = in.read( buf )) > 0) { out.write( buf, 0, len ); } } in.close(); out.close(); } catch (IOException iOException) { } XSSimpleType st = null; try { XSOMParser parser = new XSOMParser(); parser.parse( localXMLSchema ); XSSchemaSet schemaSet = parser.getResult(); XSSchema xsSchema = schemaSet.getSchema( 1 ); st = xsSchema.getSimpleType( schemaSimpleType.getTypeName() ); } catch (Exception exp) { exp.printStackTrace( System.out ); } localXMLSchema.delete(); return st; }
Example 5
Source File: SchemaGenerator.java From jumbune with GNU Lesser General Public License v3.0 | 3 votes |
public boolean updateSchema(String schemaPath, Map<String, XmlElementBean> elementMap) throws SAXException, ParserConfigurationException{ File file = new File(schemaPath); try { Map<String,String> uriMapping = new HashMap<String,String>(); SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setNamespaceAware(true); XMLReader xr = spf.newSAXParser().getXMLReader(); xr.setContentHandler(new LocalContentHandler(uriMapping)); xr.parse(file.getPath()); XSOMParser parser = new XSOMParser(); parser.parse(file); XSSchemaSet schemaSet = parser.getResult(); XSSchema xsSchema = schemaSet.getSchema(1); StringWriter string = new StringWriter(); //TODO - list to map JumbuneSchemaWriter schemaWriter = new JumbuneSchemaWriter(string,elementMap,uriMapping); schemaWriter.schema(xsSchema); FileWriter fw = new FileWriter(schemaPath); fw.write(string.toString()); fw.close(); return true ; } catch (FactoryConfigurationError | IOException e) { LOGGER.error(e.getMessage()); return false; } }