[
https://issues.apache.org/jira/browse/XMLBEANS-573?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
PJ Fanning updated XMLBEANS-573:
--------------------------------
Description:
See [https://bz.apache.org/bugzilla/show_bug.cgi?id=64837]
CTText is in poi-ooxml-full/poi-ooxml-lite and is generated using XMLBeans.
{noformat}
CTText tmpTextNode = CTText.Factory.newInstance();
tmpTextNode.setStringValue("A");
XmlOptions opts = new XmlOptions();
opts.setSaveOuter();
opts.setSaveNoXmlDecl();
System.out.println(tmpTextNode.xmlText(opts));{noformat}
This prints
{noformat}
<xml-fragment>A</xml-fragment>{noformat}
It would be nice to have an XmlOptions option that allowed this to be printed as
{noformat}
<text
xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">A</text>{noformat}
I hit a similar issue in some code I was writing and had to work around it with
this method
{noformat}
static String stripXmlFragmentElement(String xml) throws IOException,
SAXException, ParserConfigurationException, TransformerException {
String startTag = "xml-fragment";
int pos = xml.indexOf(startTag);
if (pos >= 0) {
Document doc =
XMLHelper.getDocumentBuilderFactory().newDocumentBuilder().parse(new
InputSource(new StringReader(xml)));
NodeList list = doc.getDocumentElement().getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
if (list.item(i) instanceof Element) {
try (StringWriter sw = new StringWriter()) {
Transformer transformer = XMLHelper.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.transform(new DOMSource(list.item(i)), new
StreamResult(sw));
return sw.toString();
}
}
}
return xml.substring(pos + startTag.length());
}
return xml;
}{noformat}
was:
See [https://bz.apache.org/bugzilla/show_bug.cgi?id=64837]
CTText is in poi-ooxml-full/poi-ooxml-lite and is generated using XMLBeans.
CTText tmpTextNode = CTText.Factory.newInstance();
tmpTextNode.setStringValue("A");
XmlOptions opts = new XmlOptions();
opts.setSaveOuter();
opts.setSaveNoXmlDecl();
System.out.println(tmpTextNode.xmlText(opts));
This prints
{noformat}
<xml-fragment>A</xml-fragment>{noformat}
It would be nice to have an XmlOptions option that allowed this to be printed as
{noformat}
<text
xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">A</text>{noformat}
I hit a similar issue in some code I was writing and had to work around it with
this method
{noformat}
static String stripXmlFragmentElement(String xml) throws IOException,
SAXException, ParserConfigurationException, TransformerException {
String startTag = "xml-fragment";
int pos = xml.indexOf(startTag);
if (pos >= 0) {
Document doc =
XMLHelper.getDocumentBuilderFactory().newDocumentBuilder().parse(new
InputSource(new StringReader(xml)));
NodeList list = doc.getDocumentElement().getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
if (list.item(i) instanceof Element) {
try (StringWriter sw = new StringWriter()) {
Transformer transformer = XMLHelper.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.transform(new DOMSource(list.item(i)), new
StreamResult(sw));
return sw.toString();
}
}
}
return xml.substring(pos + startTag.length());
}
return xml;
}{noformat}
> add XmlOptions so that xmlText(XmlOptions) method can be made to output more
> accurate XML
> -----------------------------------------------------------------------------------------
>
> Key: XMLBEANS-573
> URL: https://issues.apache.org/jira/browse/XMLBEANS-573
> Project: XMLBeans
> Issue Type: Improvement
> Affects Versions: Version 2.6, Version 4.0.0, Version 5.0.1
> Reporter: PJ Fanning
> Priority: Major
>
> See [https://bz.apache.org/bugzilla/show_bug.cgi?id=64837]
> CTText is in poi-ooxml-full/poi-ooxml-lite and is generated using XMLBeans.
>
> {noformat}
> CTText tmpTextNode = CTText.Factory.newInstance();
> tmpTextNode.setStringValue("A");
> XmlOptions opts = new XmlOptions();
> opts.setSaveOuter();
> opts.setSaveNoXmlDecl();
> System.out.println(tmpTextNode.xmlText(opts));{noformat}
> This prints
> {noformat}
> <xml-fragment>A</xml-fragment>{noformat}
> It would be nice to have an XmlOptions option that allowed this to be printed
> as
> {noformat}
> <text
> xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">A</text>{noformat}
>
>
> I hit a similar issue in some code I was writing and had to work around it
> with this method
>
> {noformat}
> static String stripXmlFragmentElement(String xml) throws IOException,
> SAXException, ParserConfigurationException, TransformerException {
> String startTag = "xml-fragment";
> int pos = xml.indexOf(startTag);
> if (pos >= 0) {
> Document doc =
> XMLHelper.getDocumentBuilderFactory().newDocumentBuilder().parse(new
> InputSource(new StringReader(xml)));
> NodeList list = doc.getDocumentElement().getChildNodes();
> for (int i = 0; i < list.getLength(); i++) {
> if (list.item(i) instanceof Element) {
> try (StringWriter sw = new StringWriter()) {
> Transformer transformer = XMLHelper.newTransformer();
>
> transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
> transformer.transform(new DOMSource(list.item(i)), new
> StreamResult(sw));
> return sw.toString();
> }
> }
> }
> return xml.substring(pos + startTag.length());
> }
> return xml;
> }{noformat}
>
>
>
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]