[xsde-users] Insert Raw XML with XSD/e serialization

Samuel Friedman samuel.friedman at cammlab.org
Mon Nov 28 15:13:30 EST 2016


Hello!

I have been working extensively with XSD/e's hybrid examples of wildcard
(both with custom types and custom data). I have an a complexType that is:

<xs:complexType name="custom" mixed="true">
  <xs:sequence>
    <xs:any maxOccurs="unbounded" minOccurs="0" processContents="skip"/
  </xs:sequence>
</xs:complexType>

In short, I want to have in an element of type custom that allows me to put
in any XML or plain text or combination thereof that I want. I finally
managed to get just plain text inserted using serializer_base's
_characters() function.

Some sample code using the custom data compiler flag:

  common::custom *custom_test = new common::custom;  // Create custom object
  string *hw_test = new string("hello_world"); // Make a hello world string
  custom_test->custom_data().push_back((void *)(hw_test));  // Insert hello
world
  larger_element_previously_defined->custom(custom_test) // Insert custom
text

This creates an element:
<custom>hello_world</custom>

This is exactly what I want. But when I try to insert XML, the serializer
escapes the XML text via genx, i.e. it converts "<a>Hi</a>" to
"&lt;a&gt;Hi&lt;/a&gt;".

I want to have created:
<custom>
  <a>Hi</a>
</custom>

and not:
<custom>&lt;a&gt;Hi&lt;/a&gt;</custom>

I'll happily give up the extra whitespace for now if I could just get the
XML inserted.

Now the XML I want to insert will most likely not be defined by my XML
schemas and may very well not be defined according to any XML schema (e.g.
may be defined by Relax NG schemas), so using XSD/e to parse this data is
not an option. (I already do this to merge XML files together that obey my
XML schemas.)

I'm more than willing to test that the string I want to insert is well
formed XML and I would love to have some easy code to do so. But I need to
be able to write everything down first. There's no reason to test for if
the XML is well formed if I cannot output it.

How do I get around escaping? The only way I could see this would be to
create a modified versions of genx.c's genxAddText function, context.cxx's
context::characters function, and elements.ixx's
serialize_base::_characters function. context.cxx and elements.ixx are the
ones in serializer. I feel like there should be a better way.

Thank you in advance,
Sam

-- 
Dr. Samuel H. Friedman
Postdoctoral Scholar - Research Associate

Lawrence J. Ellison Institute for Transformative Medicine of USC
USC Center for Applied Molecular Medicine
University of Southern California
2250 Alcazar St, Rm 259
Los Angeles, CA 90089-9075
Phone: 323-442-2531 | FAX: 323-442-2764
Email: samuel.friedman at cammlab.org


More information about the xsde-users mailing list