Converting object to XML

I am using the following code to convert an object into XML:
public function objectToXML(obj:Object, qname:String="root"):XML
               var qName:QName = new QName(qname);
               var xmlDocument:XMLDocument = new XMLDocument();
               var simpleXMLEncoder:SimpleXMLEncoder = new SimpleXMLEncoder(xmlDocument);
               var xmlNode:XMLNode = simpleXMLEncoder.encodeValue(obj, qName, xmlDocument);
               var xml:XML = new XML(xmlDocument.toString());
               return xml;
The resultant XML will have nodeName "item". Is it possible to customize it?
Thanks

If it is a simple object, maybe build up a string on your own.

Similar Messages

  • WD(ABAP) - How to convert PDF object to XML

    I know there is a way available to converting PDF object to XML in JAVA. However how to achieve this goal in ABAP?
    In Web Dynpro ABAP, I can bind a context attribute to the pdfSource property of interactive form element. There also should be method to able to convert the binary content of this attribute to XML format, right? Does anyone know it?
    Your help would be greatly appreciated.

    Hi all,
    As an extension to Fred's question, is it possible to later use the generated XML data and present it in a PDF template?  It used to be possible using the FDF format, but Adobe seem to have discontinued that. 
    My basic requirement is to send the form data to a third party in XML format and for them to be able to view it in human-readable format, preferably using a PDF as a template. 
    Is this possible?
    Thanks,
    Jonathan

  • Converting Document object into XML file

    I was wondering how to convert a document object to XML file? I have read the documentation about document and Node but nothing explains the procedure of the conversion. Ive been told that it can be done, but not sure how. I have converted an XML file into Document by parsing DocumentBuilder. Just not sure how to do the reverse. Any help appreciated.

    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer trans = tf.newTransformer();
    trans.transform(new DOMSource(yourDOMsRootNode), new StreamResult(new FileOutputStream(yourFileName)));or something a lot like that.

  • How to convert Java Objects into xml?

    Hello Java Gurus
    how to convert Java Objects into xml? i heard xstream can be use for that but i am looking something which is good in performance.
    really need your help guys.
    thanks in advance.

    There are apparently a variety of Java/XML bindings. Try Google.
    And don't be so demanding.

  • Design pattern for converting multiple complex Java objects to XML

    What is the traditionally accepted high performance mechanism for converting Java objects to XML? Some options I have explored are:
    1. SAX-JAXP
    2. DOM-JAXP
    3. JAXB
    4. Castor
    Which of these usually performs the best for large, complex objects which contain multiple subobjects?
    Thanks.

    Take a look at XStream. It will simplify your life considerably.
    Typical code snipped
    XStream xStream = new XStream();
    xStream.toXML(someJavaObject);That's it. Regarding the others...
    1. SAX-JAXP
    Can be used for XML -> Java Objects, but you have to write significant amounts of ugly, high maintainenance code
    2. DOM-JAXP
    Slower and more memory intensive than SAX because you need to read the whole object into memory first. Just as ugly and high maintenance.
    3. JAXB
    Actually very good for going from a POJO to XML, but rubbish in the opposite direction. The worst part is it adds an extra step to your build process as you need to tell it to generate and compile the source for doing this.
    4. Castor
    Not used it since JAXB came out. Works pretty much in the same way but also supports XML -> POJOs.

  • Objects to XML

    I use XStream to parse the following Objects to XML, the problem is what to do with:
    class Tag {
    @XStreamAsAttribute
    List<SubTag1> st1 = new ArrayList<SubTag1>();
    @XStreamAsAttribute
    List<SubTag2> st2 = new ArrayList<SubTag2>();
    ...When the class Tag is converted to XML it will always contain both a 'st1' and 'st2' even when I only
    have a Tag that ONLY contains 'st1'.
    Tag should be able to contain:
    1) List of SubTag1
    or
    2) List of SubTag2
    or
    3) List of SubTag1 and List of SubTag2
    How do I make sure to only process the Lists if they contains elements?

    Looks like you need a converter, for more info you could try the [XStream mailing list|http://xstream.codehaus.org/list-user.html].

  • Converting Javabeans into XML format

    HI,
    I have wrote program that will read input from users then stored them in javabeans. I used the serialize function to create xml file from the javabeans.
    public static void CreateXML(LocationRequest location)
              try
         // Serialize object into XML
         XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(
    new FileOutputStream("test.xml")));
         encoder.writeObject(location);
         encoder.close();
         } catch (FileNotFoundException e) {
    The output file is as follows :
    <?xml version="1.0" encoding="UTF-8"?>
    <java version="1.4.1_05" class="java.beans.XMLDecoder">
    <object >
    <void property="address">
    <string>21212122</string>
    </void>
    <void property="originatorId">
    <string>Anu</string>
    </void>
    </object>
    </java>
    Could anyone has idea on how i can change the above xml file into another new xml format like below:-
    <address> 21212122</address>
    <originatorId> "Anu "</originatorId>
    Cheers,
    Bambli

    The quickest way would be to use XSLT. Write a stylesheet that converts your 1st format to your 2nd format.
    Here's an example stylesheet. (I'm a little rusty on my XSL so you'll want to test this.)
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="xml" encoding="UTF-8"/>
      <!-- simply copy the message to the result tree -->
      <xsl:template match="/java/object/void/@property">
        <xsl:element name="local-name()">
          <xsl:value-of select="text()"/>
        </xsl:element>
      </xsl:template>
    </xsl:stylesheet> Feed this to a transformer as follows:
    javax.xml.transform.TranformFacotry factory = javax.xml.transform.TransformerFactory.newInstance();
    javax.xml.transform.stream.StreamSource source = new javax.xml.transform.stream.StreamSource(new java.io.File("yourstylesheet.xsl"));
    javax.xml.transform.Transformer xformer =factory.newTransformer(source);
    xformer.transform(new javax.xml.transform.stream.StreamSource(new java.io.File("yourbean.xml")),new javax.xml.transform.stream.StreamResult(new java.io.File("yourconverted.xml")));Its that simple.
    Cliff

  • Converting PDF to XML

    Hi All,
        I'm having one PDF File in my MIME Object. I want to Convert it to XML. How to do that ?
    Please help me in this regard.
    Regards,
    Padmam.

    hi check out this link
    XI: Read data from PDF file in Sender Adapter

  • Convert ArrayList into XML file

    Hi,
    Can anyone tell me how to convert ArrayList to XML file and save that file.
    Manoj

    There is an easy to understand example here:
    http://totheriver.com/learn/xml/code/XMLCreatorExample.java.
    You only have to replace Book objects from example with objects you need.

  • WBEM SDK - Mapping CIM Object to XML

    Hi all !
    In Sun WBEM SDK such classes as CIMClass, CIMProperty, CIMInstance have
    methods toXML(.....).
    Where can I find specification, used for CIM-to-XML mapping in Sun WBEM SDK?
    I will appreciate any assistance you might be able to offer me.
    Thank you in advance for your attention.
    Please, mail me on [email protected]
    Sincerely yours,
    Ihor Krivenchuck

    To construct an object from XML, builder pattern looks like a good option. Here is a quick design
    public class XMLCoder{
    public static Object decode(InputSream in, XMLBeanMapper xm) throws some_exception_if_ASM_object_is_in_inconsistent_state {
    public static void encode(OutputStream out, XMLBeanMapper){
    public class BeanProperty{
    private String name;
    priavte String value;
    .. cons,accessors and muatators ...
    public interface XMLBeanMapper{
    public void setProperty(BeanProperty bp);
    public Object getObject() throws some_exception_if_ASM_object_is_in_inconsistent_state ;
    public BeanProperty getNextProperty();//returns null if no more property needs to be converted to xml
    for each class that needs conversion to and from XML, you need a XMLBeanMapper class.
    XMLCoder.encode parses XML, creates a BeanProperty from each element and calls setProperty of XMLBeanMapper. The XMLBeanMapper calls necessary method of your ASM object to set the value. When it is done with parsing the xml document, it calls the getObject on the XMLBeanMapper and returns the object or throws exception if needed.
    XMLCoder.decode keeps calling the getNextProperty unless it returns null. It writes necessary xml element from the data provided by the BeanProperty instance.
    Depending on how complex your xml is you will probably need to change the BeanProperty class to keep the XMLcoder generic. For example to handle child elements, you may chain BeanProperty instances, or if the XML may have arbitrarily more information for a property than a name-value pair, you may need to use a hashtable.
    Benefits:
    You have a generic class to parse XML
    The unique XmlBeanMapper implementation for each ASM type will be pretty simple. You can have a generic XmlBeanMapper implementation when the xml elements contains the name of the method
    Disadvantages:
    You need to write and maintain a XMLBeanMapper implementation for each type of ASM class.

  • Is it possible to convert HTML to XML in as2?

    Hi,
    I am trying to develop a stock widget to use in my mobile using flashlite 2.x.
    I have chosen "http://charting.nasdaq.com" to obtain 5days chart /6months chart..
    But I am not able to use XML object for this and parse.. The values are in table format.. So I have to use LoadVars.. but writing a AS2 code
    to obtain values like High/Low price of the stock or volume is very lengthy since the data obtained are not in XML format..
    i tried this
    var example_xml:LoadVars = new LoadVars();
    example.ignoreWhite = true;
    example_xml.load("http://charting.nasdaq.com/ext/charts.dll?2-1-14-0-0-75-03NA000000www-&SF:4|5-WD=539-HT=39 5--XTBL-");
    example_xml.onLoad = function(success) {
         if (success == true) {
              trace(example_xml);
    Is it possible to convert them to xml and use relevent methods or xml properties?
    If I use example_xml:XML = new XML() then tracing example_xml (as above) doesn't give any data
    Any help?

    I had a project a few years ago where I converted 10s of thousands of TestStand HTML files from TS 1.0 and 3.0.
    Most of what I did is specific to our internal data structures, but I'll try to help get you started.
    The general idea is to pick out the report header and data sections from each file, then eliminate the HTML formatting.
    The attached file will extract the Report Header and data sections.
    To use this, you will need to download this additional VI that I posted here in the regex board a few years ago.
    http://forums.ni.com/t5/BreakPoint/Regular-Expressions-Board/m-p/1269088#M14343
    Here is one more file that will parse out each data record and dtermine it's Name, status, type value, limits and duration/timestamp info
    Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
    If you don't hate time zones, you're not a real programmer.
    "You are what you don't automate"
    Inplaceness is synonymous with insidiousness
    Attachments:
    Parse TestStand HTML.vi ‏42 KB
    Parse TestStand HTML Data Section.vi ‏55 KB

  • BPM Objects to XML

    Hello everyone,
    this could seem simple but even for me is not. I want obtain XML data coming out from my BPM Object. Basically what I want is something like the XML Object can do: use some sort of generateXMLFor() method but I cannot figure how to realize it without doing a lot of work that is just customized on my object structure.
    I've some database tables catalogued into ALBPM, for which I've created heirs objects. These objects are actually "contained" into a main object as attributes of it. In my obj I've some method that does some work on the tables heirs in order to manage data. Do not mind on how the data will be read or written, let's suppose we have the big object filled with data. I want to convert data into XML generating tags named as the relative attribute and containing the attribute's values. How this can be done?
    Any kind of hint will be really apreciated.
    Thanks a lot
    G

    Thanks! It was appliable for me!
    Just to add some information if someone will need something similar: there is also the inverse method that creates your object from an XML source. The thing that is not relly obvious is that you have to pass the type of your destination object to the method. :)
    Bye

  • How to transform common object to xml string

    I know that I can import xml dtd a the common data type in iStudio. However, does anyone know how to serialize it back to the xml string during the field mapping? Is it even possible?
    Thanks,
    Edward

    Thanks Stuart for your reply. What I'm trying to do is to convert the xml message from the common view object to JMS Text Message. I declared the application data type as AQ$JMS_TEXT_MESSAGE and I try to map the common data type which is I imported from dtd to the application JMS type. During the mapping I need to serialize the common data type object back to xml string, so I can copy it to text_vc field defined in JMS Text Message (String type).
    Or do you know any other alternative to convert from RAW XML payload type to JMS payload type in iStudio?
    Thanks,
    Edward

  • Representing Objects as XML

    Hi,
    I need to convert a runtime Object into an XML representation. Does anyone know the best way to do this? I have looked at implementing XMLReader and generating SAX events, but this assumes a stream based input. Is it possible to describe an Object as XML using the Java API's or should I just do it manually ?
    Thanks
    Steve.

    maybe you should check out new features in j2se v1.4, like http://www-106.ibm.com/developerworks/java/library/j-mer0731/

  • How to combine "Object-to-XML (OXM)" and "Direct to XML Type" mapping?

    hi
    If I have an XMLType column in my table (wich I can map using TopLink) and I have defined the structure of the contents of this XMLType column using XML Schema (wich I can map using Toplink), how can I combine both types of TopLink mappings "as transparently as possible"?
    for "Object-to-XML (OXM)" mapping
    see http://www.oracle.com/technology/products/ias/toplink/technical/tips/ox/index.htm
    for "Direct to XML Type" mapping
    see http://www.oracle.com/technology/products/ias/toplink/doc/1013/main/_html/relmapun004.htm#CHDFIFEF
    thanks
    Jan Vervecken

    Thanks for your reply James Sutherland.
    Although I haven't used a "TopLink Converter" before, this seems like a good idea.
    The thing is that the "TopLink Workbench Editor" for my "Direct to XML Type" mapping doesn't have a "Converter" tab, some other mapping type editors do have such a "Converter" tab.
    I'm not sure if I completely understand how such a "TopLink Converter" is supposed to work. How many attributes do I need in the "XMLRow" Java object for the "MY_XML" column in the "XML_TABLE" table I try to map to?
    I suppose I should try to get a situation where the "XMLRow" Java object has an "myXML" attribute of Java class type "MyXML" (where "MyXML" has been mapped to an XML Schema), not?
    So do I also still need an attribute "myXMLDocument" of type org.w3c.dom.Document as I do now for the "Direct to XML Type" mapping?
    Oh, by the way ... for anyone who hits this forum thread looking for the reason why the TopLink Workbench reports the problem "Attribute must be assignable to java.lang.String, org.w3c.dom.Document, or org.w3c.Node" while your attribute is of such a type, read this forum post
    Re: Toplink WB 10.1.3 - Aggregate field mapping bug and XMLType question
    For me the "Direct to XML Type" mapping works fine, just ignoring the waring. This is supposed to be bug number 5071250.
    thanks
    Jan Vervecken

Maybe you are looking for