stax

Metro & StreamBuffer namespace error - am I understanding this correctly?

All, I'm (still) working on calling a WSE 3.0 .NET web service from Java/Metro 2.0. We've got the security requirements set so that we're encrypting the body & header of the messages & signing the headers. I'm able to send a request to their service & get a response, but Metro is unable to validate the signature & throws an error fro...

How to Canonicalize a Stax XML object.

Hello, i want to Canonicalize a Stax object, the program it's doing it with DOM, but dom can't manage big XML documents (like 1GB), so STAX it's the solution. The Code that i have it's: File file=new File("big-1gb.xml"); org.apache.xml.security.Init.init(); DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance(); Docu...

StAX - Setting the version and encoding using XMLStreamWriter

Hi, I am using StAX for creating XML files and then validating the file with and XSD. I am getting an error while creating the XML file: javax.xml.stream.XMLStreamException: Underlying stream encoding 'Cp1252' and input paramter for writeStartDocument() method 'UTF-8' do not match. at com.sun.xml.internal.stream.writers.XMLStre...

Formatting XML file using StAX

Hi, I am using StAX XML stream writer to write the XML file. It writes all the data in a single line. I want all the tags to be indented instead of a single line. ...

How to re-read javax.xml.stream.Source object

I need to get some xml Element qname from an javax.xml.stream.Source object first, then fully parse this xml file. How can I do this ? The colon is not a safe way to do this job, considering the source object can be DOMSource, JAXBSource, SAXSource, StAXSource, StreamSource. ...

How do I write unescaped XML outside of a CDATA

Hello I am trying to write XML data using Stax where the content itself is HTML If I try xtw.writeStartElement("contents"); xtw.writeCharacters("<b>here</b>"); xtw.writeEndElement(); I get this <contents>&lt;b&gt;here&lt;/b&gt;</contents> Then I notice the CDATA method and change my code to: xtw.writeStartElement("contents"); xt...

Unit Testing XML independent of physical XML file

Hi, My question is: In JUnit, How do I setup xml data for my System Under Test(SUT) without making the SUT read from an XML file physically stored on the file system Background: I am given a XML file which contains rules for creation of an invoice. My job is to convert these rules from XMl to Java Objects e.g. If there is a tag as be...

"Content is not allowed in prolog" when parsing perfectly valid XML on GAE

Hey guys, I've been beating my head against this absolutely infuriating bug for the last 48 hours, so I thought I'd finally throw in the towel and try asking here before I throw my laptop out the window. I'm trying to parse the response XML from a call I made to AWS SimpleDB. The response is coming back on the wire just fine; for examp...

XMLOutputStream, repairing namespaces, and attributes without namespaces

A simple task: write an element two attributes: String nsURI = "http://example.com/"; XMLOutputFactory outF = XMLOutputFactory.newFactory(); outF.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, true); XMLStreamWriter out = outF.createXMLStreamWriter(System.out); out.writeStartElement(XMLConstants.DEFAULT_NS_PREFIX, "element", nsUR...

XMLEventWriter from scratch: how do I emit xmlns attribute?

I am trying to write an XML document from scratch using the XMLEventWriter from the StAX API. I cannot figure out how to get the default namespace attribute to be emitted. For example, the default namespace URI string is "http://www.liquibase.org/xml/ns/dbchangelog/1.9". I want that to be present in my XML root element as xmlns="http:...

XMLEventWriter: how can I tell it to write empty elements?

I do not see an option within javax.xml.stream.XMLEventWriter or javax.xml.stream.XMLOutputFactory to set either up in a way so that empty elements are written (instead of explicit start and end element pairs). I see that Woodstox has a property to do this, but it is not standardized. Am I missing any obvious way to do this? ...

JAVA: gathering byte offsets of xml tags using an XmlStreamReader

Hi there, Is there a way to accurately gather the byte offsets of xml tags using the XMLStreamReader? I have a large xml file that I require random access to. Rather than writing the whole thing to a database, I would like to run through it once with an XMLStreamReader to gather the byte offsets of significant tags, and then be able t...

How to add node to existing XML Document

I'm using stax to parse my document, here is a dummy example of my XML document : <data> <video> <title lang="eng">Harry Potter</title> <price>29.99</price> </video> <book id="1"> <title lang="eng">Learning XML</title> <price>39.95</price> </book> <book id="n"> <title lang="eng">Learning XML</title> <price>39.95</price>...

Indentation issues with Staxmate API

I am using Staxmate API to generate XML file. After reading the tutorial: http://staxmate.codehaus.org/Tutorial I tried making the changes in my code. At last I added the call doc.setIndentation("\n ", 1, 1); Which causes the newly generated XML file to be empty! Without this method call entire XML file gets generated as expected. ...

Convert XML file to CSV in java

@Before There will be probably some duplicate questions suggestions, I don't think that is the case maybe read this first, I'll try to be as brief as possible. Title gives basic idea. Here is an example XML(case 1) : <root> <Item> <ItemID>4504216603</ItemID> <ListingDetails> <StartTime>10:00:10.000Z</Sta...

How to get element only elements with values Stax

I'm trying to get only elements that have text, ex xml : <root> <Item> <ItemID>4504216603</ItemID> <ListingDetails> <StartTime>10:00:10.000Z</StartTime> <EndTime>10:00:30.000Z</EndTime> <ViewItemURL>http://url&lt;/ViewItemURL&gt; .... </item> It should print ...

How to choose an implementation sjsxp and wstx if both of them are in the classpath

Axis2 relies on woodstox's wstx while other part of my project has tested heavily with sjsxp and we can't afford to rerun the same test. Now, there is a problem with parsing SOAP message with axis2 that if I take away sjsxp, the problem is gone. Is there a way to tell axis2 to use the wstx implementation and leave the rest of the proje...

Scala + stax compile problem during deploy process

Hello. I developed an app in scala-ide (eclipse plugin), no errors or warnings. Now I'm trying to deploy it to the stax cloud: $ stax deploy But it fails to compile it: compile: [scalac] Compiling 2 source files to /home/gleontiev/workspace/rss2lj/webapp/WEB-INF/classes error: error while loading FlickrUtils, Scala signature Flick...

How should I use Stax2 Validation API against a W3 Schema

I am using com.ctc.wstx.stax.WstxOutputFactory to generate XML. I am running wstx-asl-3.2.4 I need to start validating the generated XML against a W3 Schema. When I create an instance of org.codehaus.stax2.validation.XMLValidationSchemaFactory like this private final static XMLValidationSchemaFactory xsdFact= XMLValidationSchemaF...

Why does XMLEventReader report a CHARACTERS event that contains markup?

I have an XMLEventReader. It has been built from an XMLInputFactory with the "UTF8" encoding. I am using it to read an XML file whose "encoding" attribute is set to "UTF-8". I have verified that the XML file views correctly under Firefox. When you view the page encoding, it says that it is UTF-8. I have set the XMLEventReader to coa...