Re: How to add standalone attribute
Kevin Krouse <[email protected]> Thu, 12 May 2011 16:27:08 -0700
| Newsgroups | gmane.text.xml.xmlbeans.user |
|---|---|
| Message-ID | <[email protected]> |
Here is a rough patch. I haven't tested it extensively. There is a bug in loading a document the standalone decl as can be seen in the output from running test.java: Original xml: <hello/> Default: <?xml version="1.0" encoding="UTF-8"?> <hello/> set standalone=true: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <hello/> set standalone=false: <?xml version="1.0" encoding="UTF-8" standalone="no"?> <hello/> remove standalone <?xml version="1.0" encoding="UTF-8"?> <hello/> Original xml: <?xml version='1.0' standalone='yes'?> <hello/> Default: <?xml version="1.0" encoding="UTF-8"?> <hello/> set standalone=true: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <hello/> set standalone=false: <?xml version="1.0" encoding="UTF-8" standalone="no"?> <hello/> remove standalone <?xml version="1.0" encoding="UTF-8"?> <hello/> On Thu, May 12, 2011 at 5:12 AM, pgillen <[email protected]> wrote: > I tried that without effect. Be interested to hear others experience. > -paul- > > --------- > Paul Gillen > ------------------------------ > *From: * Jacob Danner <[email protected]> > *Date: *Wed, 11 May 2011 18:24:34 -0700 > *To: *<[email protected]> > *ReplyTo: * [email protected] > *Subject: *Re: How to add standalone attribute > > Take a look at XmlDocumentProperties.setstandalone(...) > -jacobd > On May 10, 2011 11:47 AM, "Roman Kashitsyn" <[email protected]> > wrote: > > > > How can I add standalone="yes" attribute to "xml" processing instruction > when > > saving xmlbean? Suppose I had an xmlbean and I want to save it in the > > following way: > > > > > > XmlOptions xmlOptions = new XmlOptions(); > > xmlOptions.setSaveOuter(); > > xmlOptions.setSaveSyntheticDocumentElement(new QName(NAMESPACE_URI, > > TAG_NAME, PREFIX)); > > > > /* some magic happens here */ > > > > bean.save(anOutputStream, xmlOptions) > > > > > > Now I get the following result: > > > > <?xml version="1.0" encoding="utf-8"?> > > <!-- perfectly well xml file --> > > > > > > How can I get the following result: > > > > <?xml version="1.0" encoding="utf-8" standalone="yes"?> > > <!-- perfectly well xml file --> > > > > ??? > > -- > > View this message in context: > http://old.nabble.com/How-to-add-standalone-attribute-tp31586761p31586761.html > > Sent from the Xml Beans - User mailing list archive at Nabble.com. > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
standalone.patch
(application/octet-stream, 2.8 KB)
diff --git a/src/store/org/apache/xmlbeans/impl/store/Locale.java b/src/store/org/apache/xmlbeans/impl/store/Locale.java
index ebf96a2..5ec05ff 100755
--- a/src/store/org/apache/xmlbeans/impl/store/Locale.java
+++ b/src/store/org/apache/xmlbeans/impl/store/Locale.java
@@ -961,7 +961,6 @@ public final class Locale
encoding = doc.getCharacterEncodingScheme();
version = doc.getVersion();
standAlone = doc.isStandalone();
- standAlone = doc.isStandalone();
if (lineNums)
lineNumber(xe, context);
diff --git a/src/store/org/apache/xmlbeans/impl/store/Saver.java b/src/store/org/apache/xmlbeans/impl/store/Saver.java
index 1344aaa..8c0712f 100755
--- a/src/store/org/apache/xmlbeans/impl/store/Saver.java
+++ b/src/store/org/apache/xmlbeans/impl/store/Saver.java
@@ -949,9 +949,16 @@ abstract class Saver
if (version == null)
version = "1.0";
+ Boolean standalone = null;
+ if (props != null && props.get(XmlDocumentProperties.STANDALONE) != null)
+ standalone = Boolean.valueOf("yes".equals(props.get(XmlDocumentProperties.STANDALONE)));
+
emit( "<?xml version=\"" );
emit( version );
- emit( "\" encoding=\"" + encoding + "\"?>" + _newLine );
+ emit( "\" encoding=\"" + encoding + "\"");
+ if (standalone != null)
+ emit( " standalone=\"" + (standalone.booleanValue() ? "yes" : "no") + "\"");
+ emit( "?>" + _newLine );
}
}
diff --git a/src/xmlpublic/org/apache/xmlbeans/XmlDocumentProperties.java b/src/xmlpublic/org/apache/xmlbeans/XmlDocumentProperties.java
index f61fad5..58c15a6 100644
--- a/src/xmlpublic/org/apache/xmlbeans/XmlDocumentProperties.java
+++ b/src/xmlpublic/org/apache/xmlbeans/XmlDocumentProperties.java
@@ -75,11 +75,16 @@ public abstract class XmlDocumentProperties
* Sets the standalone property.
* @param standalone whether standalone is true or not
*/
- public void setStandalone ( boolean standalone ) { put( STANDALONE, standalone ? "true" : null ); }
+ public void setStandalone ( boolean standalone ) { put( STANDALONE, standalone ? "yes" : "no" ); }
/**
- * Returns the standalone property
+ * Removes the standalone property.
*/
- public boolean getStandalone ( ) { return get( STANDALONE ) != null; }
+ public void removeStandalone ( ) { remove( STANDALONE ); }
+
+ /**
+ * Returns the standalone property. Defaults to true if not set.
+ */
+ public boolean getStandalone ( ) { Object value = get( STANDALONE ); return value == null || "yes".equals(value); }
/**
* Sets the DOCTYPE name use in the <!DOCTYPE> declaration.
test.java
(application/octet-stream, 1.1 KB) - not displayed