jaxp

How can I validate documents against Schematron schemas in Java?

一个人想着一个人 提交于 2019-12-04 11:47:09
问题 As far as I can tell, JAXP by default supports W3C XML Schema and RelaxNG from Java 6. I can see a few APIs, mostly experimental or incomplete, on the schematron.com links page. Is there an approach on validating schematron in Java that's complete, efficient and can be used with the JAXP API? 回答1: Jing supports pre-ISO Schematron validation (note that Jing's implementation is based also on XSLT). There are also XSLT implementations that can be very easily invoked from Java. You need to decide

Difference SAXParserFactory XMLReaderFactory. Which one to choose?

你说的曾经没有我的故事 提交于 2019-12-04 09:31:18
问题 Both of them seem to have the same purpose (create a XMLReader). Some Tutorials contain the one, some the other. SAXParserFactory: http://docs.oracle.com/javase/7/docs/api/javax/xml/parsers/SAXParserFactory.html seems to be more configurable more boiler-plate code officially supported api example code: // SAXParserFactory SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); XMLReader reader = parser.getXMLReader(); reader.parse(new InputSource(

Workaround for XMLSchema not supporting maxOccurs larger than 5000

青春壹個敷衍的年華 提交于 2019-12-04 07:31:52
My problem is with parsing an XSD Schema that has elements with maxOccurs larger than 5000 (but not unbounded ). This is actually a know issue in either Xerces (which I'm using, version 2.9.1) or JAXP, as described here: http://bugs.sun.com/view_bug.do;jsessionid=85335466c2c1fc52f0245d20b2e?bug_id=4990915 I already know that if I changed the maxOccurs numbers in my XSD from numbers larger than 5000 to unbounded all works well. Sadly, this is not an option in my case (I cannot meddle with the XSD file). My question is: Does someone know some other workaround in Xerces for this issue? Or Can

Java/XSD parsing

我只是一个虾纸丫 提交于 2019-12-04 03:15:01
I doubt if there is something like this but I thought to ask though: Does anyone know if there is a library in Java that reads an xsd file and "creates" the defined elements e.g. in a String format to use in the code? E.g. read in the following schema: <?xml version="1.0" encoding="utf-8"?> <xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="Address"> <xs:complexType> <xs:sequence> <xs:element name="Street" type="xs:string" /> <xs:element name="Town" type="xs:string" /> <xs:element name="Country" type="xs:string" minOccurs="0" /> </xs

Detecting System.setProperty method invocations

流过昼夜 提交于 2019-12-03 20:18:20
I'm facing a conundrum here. One of the applications that I've developed is loading an incorrect implementation of the DocumentBuilderFactory class of JAXP. This behavior was later deduced to be resulting from another class in different application built by a different team/company. The said class had changed the preferred DocumentBuilderFactory class upon loading, by inclusion of a static block similar to the one below: static { System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "a new factory"); } If one goes by the Javadocs of the DocumentBuilderFactory.newInstance method, it

Parsing Schema in Java With imports and includes?

戏子无情 提交于 2019-12-03 20:10:30
问题 I'm attempting to parse load a rather complicated XML schema into a Schema object in Java so I can do some validation on XML messages. My code looks similar to this: SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = factory.newSchema(new StreamSource(new File("schema/schema.xsd"))); My schema has quite a few imports: <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="base_1"> <xs:import

Get an attribute of a dom node

你。 提交于 2019-12-03 14:24:56
问题 I am trying to get an attribute of an xml node example: <Car name="Test"> </Car> I want to grab the name attribute of the car node. DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(configFile); doc.getDocumentElement().normalize(); NodeList layerConfigList = doc.getElementsByTagName("CAR"); Node node = layerConfigList.item(0); // get the name attribute out of the node. this is where i get stuck because

How can I validate documents against Schematron schemas in Java?

别等时光非礼了梦想. 提交于 2019-12-03 08:13:37
As far as I can tell, JAXP by default supports W3C XML Schema and RelaxNG from Java 6 . I can see a few APIs, mostly experimental or incomplete, on the schematron.com links page . Is there an approach on validating schematron in Java that's complete, efficient and can be used with the JAXP API? Jing supports pre-ISO Schematron validation (note that Jing's implementation is based also on XSLT). There are also XSLT implementations that can be very easily invoked from Java. You need to decide what version of Schematron you are interested in and then get the corresponding stylesheet - all of them

Make JAXB go faster

半世苍凉 提交于 2019-12-03 04:31:02
问题 I have a 8 Meg file. Marshalling using JAXB takes 1082ms, using DOM takes 862ms, using SAX takes 438ms. This is using all defaults with JDK 1.6, no extra configuration such as using woodstox is used. In an effort, to get better performance from JAXB, I try to make it use SAX parsing by doing... FileReader fr = new FileReader("myfile.xml"); JAXBContext jc = JAXBContext.newInstance(MyObjectList.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); XMLInputFactory xmlif = XMLInputFactory

Get an attribute of a dom node

一笑奈何 提交于 2019-12-03 04:13:19
I am trying to get an attribute of an xml node example: <Car name="Test"> </Car> I want to grab the name attribute of the car node. DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(configFile); doc.getDocumentElement().normalize(); NodeList layerConfigList = doc.getElementsByTagName("CAR"); Node node = layerConfigList.item(0); // get the name attribute out of the node. this is where i get stuck because the only method that looks like i can use is getAttributes() with returns a NamedNodeMap and im not sure