jaxp

How can I provide customer error messages using JAXP DocumentBuilder?

I want to provide my own message from the validation done in DocumentBuilder, rather than the one from XMLMessages.properties. Now i see that a property error-reporter needs to be set to a class which extends XMLErrorReporter. However, I've not been able to get ComponentManager from Document/Builder/Factory. Can any kind soul gimme co...

java append to file

I googled for this for a while but can't seem to find it and it should be easy. I want to append a CR to then end of an XML file that I am creating with a Transformer. Is there a way to do this> I tried the following but this resulted in a blank file? Transformer xformer = TransformerFactory.newInstance().newTransformer(); xformer.set...

Best way to close a stream an SAX parser is reading during the parsing process?

Hello dear Stackoverflow community! Let's get straight to my question: I have a socket and all input coming via this socket / stream is parsed by my SAX parser. Now, upon a certain parsing event I'd like to close the socket / stream from within my SAX event handler. Also, I want to close the stream from outside in a certain case while t...

JAXP XIncludes with xpointer() scheme

Is there a way to use the xpointer() scheme with JAXP? The Xcerces FAQ states that only element() is supported (http://xerces.apache.org/xerces2-j/faq-xinclude.html). But i need to resolve those XIncludes because i have to deal with "legacy" documents. ...

How can I validate documents against Schematron schemas in Java?

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? Thanks ...

Preserving hierarchy when converting .csv file to xml or json

Hello I have a question concerning translating data from a CSV into XML or JSON where it is essential to preserve the heirarchy of the data. For example, if I have CSV data like this: type,brand,country,quantity apple,golden_delicious,english,1 apple,golden_delicious,french,2 apple,cox,,4 apple,braeburn,,1 banana,,carribean,6 banana,...

How to validate an XML document using a RELAX NG schema and JAXP?

I would like to validate XML documents using RELAX NG schemata, and I would like to use the JAXP validation API. From Googling around, it appeared that I could use Jing and the ISO RELAX JARV to JAXP Bridge. Unfortunately, after adding both to my classpath, I can't get it to work. SchemaFactory is just throwing an IllegalArgumentExcepti...

How to get a clean Java VM on MacOS?

On MacOS (at least on SnowLeopard), the java command unconditionally adds an extra jar to the classpath: /System/Library/Frameworks/JavaVM.framework/Versions/A/Resources/.compatibility/14compatibility.jar. This jar contains a version of Apache Xerces+Xalan, unrenamed. This can cause chaotic results for applications that are trying expl...

How do I find out which JAXP implementation is in use and where it was loaded from?

I would like to provide diagnostic information about what JAXP implementation is in use, and which JAR file it was loaded from. One way to achieve this is to create in instance of, for example, a DocumentBuilderFactory, and then inspect the properties of that class: private static String GetJaxpImplementation() { DocumentBuilderFac...

What is the most memory-efficient way to emit XML from a JAXP SAX ContentHandler?

I have a situation similar to an earlier question about emitting XML. I am analyzing data in a SAX ContentHandler while serializing it to a stream. I am suspicious that the solution in the linked question -- though it is exactly what I am looking for in terms of the API -- is not memory-efficient, since it involves an identity transform ...

converting a raw file into xml file

Hello guyz, I'm working on a project under which i have to take a raw file from the server and convert it into XML file. is there any tool available in java which can help me to accomplish this task like JAXP can be used to parse the XML document ??? Thanks in Advance.... ...

XPATH Query not return result

Hi given the following Code: private void extractLink(ScriptFile file) throws SAXException, IOException, ParserConfigurationException, XPathExpressionException { Document d = this.parseFile(file); XPathFactory xpf = XPathFactory.newInstance(); XPath xpath = xpf.newXPath(); XPathExpression expr = xpath.compile("//link"); Obj...

Remove Empty Attributes from XML

Hi, I have a buggy xml that contains empty attributes and I have a parser that coughs on empty attributes. I have no control over the generation of the xml nor over the parser that coughs on empty attrs. So what I want to do is a pre-processing step that simply removes all empty attributes. I have managed to find the empty attributes,...

I need to parse non well-formed xml data (HTML)

Hi, I have some non well-formed xml (HTML) data in JAVA, I used JAXP Dom, but It complains. The Question is :Is there any way to use JAXP to parse such documents ?? I have a file containing data such as : <employee> <name value="ahmed" > <!-- note, this element is not closed, So it is not well-formed xml--> </employee> ...

Cannot validate xml doc againest a xsd schema (Cannot find the declaration of element 'replyMessage')

Hi Guyz, I am using the following code to validate an an XML file against a XSD schema package com.forat.xsd; import java.io.IOException; import java.net.URL; import javax.xml.XMLConstants; import javax.xml.transform.Source; import javax.xml.transform.stream.StreamSource; import javax.xml.validation.Schema; import javax.xml.validatio...

In XML what do you call this: //@Dohicky.0 and how to address it in Java

It's my first time parsing XML and I don't really know what I'm doing at the moment. Here's my XML: <?xml version="1.0" encoding="UTF-8"?> <MyDocument xmi:version="2.0"> <Thingamabob name="A" hasDohicky="//@Dohicky.0"> <Dingus/> </Thingamabob> <Dohicky name="B"/> </MyDocument> So what is "//@Dohicky.0" called? I understand...

JAXP Processing XML with NameSpace

Hi Iam trying to process an XML file with a namespace using JAXP/XPATH - but there is no output - any help would be great. I'm struggling with the namespace syntax... Basically I would like to process the currency and rates below in the XML file. XML FILE <gesmes:Envelope xmlns:gesmes="http://www.gesmes.org/xml/2002-08-01" xmlns="http...

Jaxp xml parsing & validation without writing to file

I've a JMS messaging app thats reading and writing to MQ queues. The message data is string form and in xml format (minus the normal header markers like the xml version etc). I'm looking at the best ways to read in, write out and validate against an xsd schema however the examples I'm coming across all talk about working with files. Is ...

Querying an HTML page with XPath in Java

Hi, Can anyone advise me a library for Java that allows me to perform an XPath Query over an html page? I tried using JAXP but it keeps giving me a strange error that I cannot seem to fix (thread "main" java.io.IOException: Server returned HTTP response code: 503 for URL: http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd). Thank...

Java and XML (JAXP) - What about caching and thread-safety?

I'd like to know which objects can be reused (in the same or different document) when using the Java API for XML processing, JAXP: DocumentBuilderFactory DocumentBuilder XPath Node ErrorHandler (EDIT: I forgot that this has to be implemented in my own code, sorry) Is it recommended to cache those objects or do the JAXP implementatio...