[xml] Newline at the end of output
- From: James Hart <beeblebrox42 gmail com>
- To: xml gnome org
- Subject: [xml] Newline at the end of output
- Date: Tue, 9 Jun 2009 13:06:19 -0600
I have a use case where I need to treat an xml document as a document fragment, I won't get into the details of why exactly, but lets make the assumption it is a valid use case for now.
This is the code I am using to get the string of a document, without the prolog into a buffer:
xmlSaveCtxtPtr saveCtxt = xmlSaveToBuffer(buffer, outputEncoding_.c_str(), XML_SAVE_NO_DECL);
xmlSaveDoc(saveCtxt, doc_);
xmlSaveFlush(saveCtxt);
//This will delete the saveCtxt pointer too.
xmlSaveClose(saveCtxt);
std::string ret((char *)xmlBufferContent(buffer));
return ret;
Where the doc was created with a literal such as '<foo>test</foo>'.
It works well except I appear to always get a newline at the end of the output. I understand that a newline doesn't make the document output invalid, however it does add extra, unneeded whitespace for my fragment which could change the meaning of the content where I am inserting this document as a fragment.
I don't want to have to hack the removal of this newline in my code if it can be helped. Is there a way to do this and not get the newline? Is there a way to output the xml string for just the root element instead of using the document approach to get around this?
Thanks,
James
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]