4

While generating an XML content, I get an empty node <node/>, and I want it to be <node></node>. (Since <node></node> is the correct form of c14n, the progress called "converting empty elements to start-end tag pairs")

How should I convert it?

There's a way hinted by Jim Garrison(Thank you) to do this, by using xmlBufferCreate, xmlSaveToBuffer, xmlSaveDoc, xmlSaveClose with xmlSaveOption: XML_SAVE_NO_EMPTY

iOS Padawan
  • 418
  • 1
  • 5
  • 16
  • Do you mean how, as in, something like String manipulation? – Benjamin Jun 12 '12 at 22:47
  • I'm wondering if there's some kind of function supported by libxml to do this? Since libxml can do c14n, there should be one handling this situation, or maybe I miss something when producing the node. – iOS Padawan Jun 12 '12 at 22:54
  • possible duplicate of [libxml2 preserve empty tags](http://stackoverflow.com/questions/10423839/libxml2-preserve-empty-tags) – hakre Feb 07 '13 at 15:02

2 Answers2

5

Take a look at the libxml2 documentation, specifically xmlSaveOption value XML_SAVE_NO_EMPTY

Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
2

I found another way which is easier when the nodes are generated under control, by simply giving value "" to the node.

iOS Padawan
  • 418
  • 1
  • 5
  • 16