Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Support for XML 1.1 #29

Closed
ghost opened this issue Jun 23, 2015 · 4 comments
Closed

Support for XML 1.1 #29

ghost opened this issue Jun 23, 2015 · 4 comments

Comments

@ghost
Copy link

ghost commented Jun 23, 2015

While investigating an issue with importing a .vcf file that was exported from OS X, we found ASCII characters that are not supported by the default XML 1.0 version generated when creating a new XCardDocument. The issue is revealed later when a backend component attempts to parse the generated XML using SAX.

I was looking for a way via ez-vcard to allow setting the XML version to 1.1 when generating the XCardDocument.

@mangstadt
Copy link
Owner

Sorry for the late response. Thank you for the suggestion. I'll look into it!

@mangstadt
Copy link
Owner

I'm not sure how invalid characters are sneaking in there. ez-vcard uses Java's XML API to create the XML document, so it should automatically escape any characters that are not supported by XML 1.0. Can you include a code sample?

As for supporting XML 1.1, the code sample below might work for you. Although, apparently, this only works with certain JVMs (according to my testing)

XCardDocument xcardDoc = ...
Document doc = xcardDoc.getDocument();

Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(OutputKeys.VERSION, "1.1");

DOMSource source = new DOMSource(doc);
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
transformer.transform(source, result);

String xml = writer.toString();

@mangstadt
Copy link
Owner

I posted a question on Stackoverflow about writing XML 1.1 document in Java. Apparently, the XML libraries bundled with the JDK are quite old, so you have to include a more up-to-date library to support 1.1.

If you add the xalan-2.7.2 library to your classpath, then you can use the code that I wrote in the above post to output an XML 1.1 document.

See: http://stackoverflow.com/a/31990430/13379

@mangstadt
Copy link
Owner

Added the ability to specify the XML version when writing xCards: 10e22e7

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

1 participant