How to represent XML inline tags in a Java class

Dear all,
I am currently dealing with the issue of how to transform an XML document into a Java representation. As far as the strucural elements are concerned, I'd represent them each one of them as a Java class. However, the XML structure also allows for inline tags, i.e. elements which specify formatting information for the text. I am looking for good ideas for how to best represent these in my Java class(es).
Let's use an example. Suppose I have something like this:
<root>
   <structure>A piece of text</structure>
   <moreStructure>A piece of <b>bold</b> text</moreStructure>
   <finalStructure>A piece of <inlineTag att="value"> more text!</inlineTag>   </finalStructure>
</root>I this case I would build four classes for the strucural elements. But how do I represent <b> and <inlineTag>? In my XML documents I have several such inline tags, each of which may also have a bunch of attributes. I am sure this has been solved cleverly before. Any help greatly appreciated.
Best regards,
N.

The XML term for "containing tags and text" is "mixed content". And XML designers generally don't care much for mixed content. You're finding out one of the reasons for that right now. They aren't elegant or clever, just inconvenient.
However sometimes you have to deal with ugly structures. This is one of them. I would represent mixed content as a list, just as you already thought of. The elements in this list would be either text or elements. So in this example:<moreStructure>A piece of <b>bold</b> text</moreStructure>you would have three entries:
1. Text "A piece of "
2. A <b> element
3. Text " text"
And when retrieving from that list you would have to use "instanceof" to see if you had a String or an element of some kind.
And if "standalone tags" versus "paired tags" is a complication, then you're looking at it wrong. XML doesn't care much about tags. Tags only exist to delimit an element, and you should be looking at elements.
I'm guessing at your non-standard terminology here: a "standalone tag" is an empty element like
, right? And "paired tags" means a non-empty element like <this>that</this>? They're all elements. The first is a "br" element and the second is a "this" element.

Similar Messages

  • How to  get the profile object in simple java class  (Property accessor)

    Hi All,
    Please guide me how to get the profile object in simple java class (Property accessor) which is extending the RepositoryPropertyDescriptor.
    I have one requirement where i need the profile object i.e i have store id which is tied to profile .so i need the profile object in the property accessor of the SKU item descriptor property, which is extending RepositoryPropertyDescriptor.
    a.I dont have request object also to do request.resolvename.
    b.It is not a component to create setter and getter.It is simple java class which is extending the RepositoryPropertyDescriptor.
    Advance Thanks.

    Iam afraid you might run into synchronization issues with it. You are trying to get/set value of property of a sku repository item that is shared across various profiles.
    Say one profile A called setPropertyValue("propertyName", value).Now another profile B accesses
    getPropertyValue() {
    super.getPropertyValue() // Chance of getting value set by Profile A.
    // Perform logic
    There is a chance that profile B getting the value set by Profile A and hence inconsistency.
    How about doing this way??
    Create PropertyDescriptor in Profile (i.e user item descriptor), pass the attribute CustomCatalogTools in userProfile.xml to that property.
    <attribute name="catalogTools" value="atg.commerce.catalog.CustomCatalogTools"/>
    getPropertyValue()
    //You have Profile item descriptor and also storeId property value.
    // Use CustomCatalogTools.findSku();
    // Use storeId, profile repository item, sku repository item to perform the logic
    Here user itemdescriptor getPropertyValue/setPropertyValue is always called by same profile and there is consistency.
    -karthik

  • How to execute a jsp instruction from a java class?

    How to execute a jsp instruction from a java class?
    Any help please.
    Thank's

    I'll detail my problem:
    Supposing that I have a jsp file called: start.jsp
    In the start.jsp I instanciated an object called global from the class Global ( for example ).
    Then, I called a custom taglib:
    <ix:mytag/>
    In the suitable tld file: the mytag is defined:
    <tag>
    <tag class>Tag1<.....
    The java file Tag1 has method:
    doStartTag(){
    // here is the problem
    global.doSomeFunctions();
    Okay, the problem is that the object gobal is not defined in the class Tag1. what to do?
    I think that I have to pass the object global as a parameter to the class Tag1. How to do that?
    Actually, the problem was to insert the follwoing in the doStartTag method:
    doStartTag(){
    pageContext.getOut().print("<%= hello world %>");
    The output is <%= hello world %> not hello world.
    Okay, the new problem is how to pass an object as a parameter to a class called from a tld file.
    Any help please.
    Thank's too much

  • Help! How to read a .txt file into a Java class and make 2D array?

    Hi guys,
    Im a newbie with arrays, just started really using them.. please bear with me if I don't seem to understand much..
    I have a .txt file that contains either a square or rectangle (random width and length).. How can I read each line into a Java class into a 2D array with rows and columns?

    Example :
    import javax.swing.*;
    import java.util.ArrayList;
    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.File;
    public class ReadInto2DArrayExample {
        public static void main(String[] args) {
            ArrayList array = new ArrayList();
            char [][] twoDimesionArray = null;
            try
                JFileChooser fileChooser = new JFileChooser();
                if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION)
                    File file = fileChooser.getSelectedFile();
                    BufferedReader reader = new BufferedReader(new FileReader(file));
                    String data;
                    //Read from file
                    while ((data = reader.readLine()) != null)
                        //Convert data to char array and add into array
                        array.add(data.toCharArray());
                    reader.close();
                    //Creating a 2D char array base on the array size
                    twoDimesionArray = new char [array.size()][];
                    //Convert array from ArrayList to 2D array
                    for (int i = 0; i < array.size(); i++)
                        twoDimesionArray[i] = (char [])array.get(i);
                    //Test the 2D Array
                    for (int y = 0; y < twoDimesionArray.length; y++)
                        char [] temp = twoDimesionArray[y];
                        for (int x = 0; x < temp.length; x ++ )
                            System.out.print(temp[x]);
                        System.out.println("");
            catch (Exception ex)
                ex.printStackTrace();
    }

  • How can i have a refrence of a java class object instance in my c++ project

    Hi!
    How can i have a refrence of a java class object instance in my c++ project. Is there a way?

    hahaxia wrote:
    The second question is the big one. The first question is half of the problem of "c++ to java" invocation and access. But the other half which is "java to c++ " invocation and access is still not solved. jni only provide the "java to c++ " DLL invocation Wrong,
    Using JNI your java classes can have methods implemented in C/C++.
    Using JNI you can call java classes.
    There is no other possible interaction between C++ and java, so it does it all.

  • How to used a JCR Data Control in Java class?

    Hi,
    I created a JCR Data Control to my UCM to obtain a treeTable with the datas. But it's impossible to create a treeTable like i want to.
    So I know how to create a treeModel to obtain the treeTable I want.
    Is there a way to used the getItems method of the dataControl in a Java Class?
    I tried this :
    BindingContext bc = (BindingContext)JSFUtils.resolveExpression("#{data}");
    DCDataControl dc = bc.findDataControl("UcmDC");
    But dc is null.
    There are some xml files (UcmDC.xml or getItems_return.xml). Is it a way to resolve my problem. And if so, how do I use?
    Best regards,
    Thomas

    please refer metalink id(305710.1)

  • How to create a Concurrent Program around a java class

    Can anyone give me the steps I need to register a concurrent program based on a java class?
    I have a java class that basically opens a jdbc connection, reads values from a table, decompresses one column, and sends all info to XML Gateway. I just need to know how to deploy this thing.
    Thanks.
    -Jason

    Check Metalink Note:305710.1

  • How to get user information in a standalone java class

    Is there a way to retrieve it in a stand alone java class (with no access to request object)? If so how do I get it?
    Thanks,
    Deepak

    Hi
    use this
    IWDClientUser currentUsers[]=WDClientUser.getClientUsers();
              //Displaying the count of logged on users
              wdComponentAPI.getMessageManager().reportSuccess("Number of logged on Users in the portal - "+(currentUsers.length-1));
              for(int i=0;i<currentUsers.length;i++){
                 if(currentUsers<i>!=null){
                     // Displaying the logged on users;
                     if(!currentUsers<i>.getLastName().equals("Guest")){
                          String first= currentUsers<i>.getFirstName();
                          wdComponentAPI.getMessageManager().reportSuccess("User - "currentUsers<i>.getFirstName()" "+currentUsers<i>.getLastName());
        //@@end

  • Is there any way to prevent web.xml from any change like java class?

    hi all,
    Is there any way to prevent web.xml from any change after making EAR(WAR)?
    One can easily make a change in web.xml and redeploy the application to get the result. Now we want to restrict the web.xml as java class for any change after making EAR(or WAR).
    Could some one help me to do this?
    thanks,
    dinesh

    hi,
    Not at development level. We want it after deploying the application on server .
    We want to create it (web.xml) at tomcat startup (or in any other web/app server ) before loading any context.
    Is there any way to run a simple java class(not servlet) on tomcat startup(before initializing the contexts)?
    Message was edited by:
    DP_java
    Message was edited by:
    DP_java

  • How to Run a .sql file from simple java class

    How to execute a .sql file consisting of Complex Queries,procedures through simple java class.
    The queries may have different delimiters,queries independant of each other.
    I am able to do with Specific De-limiter.But I need in such a way that there should not be any
    Constraints. Since My .sql may Contain different De-limiters.
    If any one can Suggest Some Solution.
    It will be Great Help.
    regards
    Anil

    Check out ibatis script runner, it' a third party library but quite handy for running sql files...
    m

  • How to pass an argument to a standalone java class in JDeveloper

    To the experienced:
    In JDeveloper when you write a java class with a main() method that takes no argument, you just right click the java file and select Run to run the program. But suppose the main() method takes arguments, how do you pass your arguments to the program? This is especially a problem as I use the studio version of JDeveloper (Versions 10.1.3.4 and 11.1.1.3) that each uses the version of JDK bundled with it, rather than the JDK (which is yet another different version) installed at the OS level of the PC.
    Many thanks for your help!
    Newman

    Hi, Puthanampatti,
    Suppose a java class has a main() method:
    <pre>
    public class FormatTerm {
    public static void main(String[] args) {
    String year = args[0];
    String semester = args[1];
    </pre>
    What I want to know is how to pass the arguments when invoking FormatTerm within JDeveloper (i.e., without going out of JDeveloper to invoke FormatTerm on a command line in DOS). I would appreciate it very much if you know how to do that in JDeveloper 11g (I use Version 11.1.1.3) and could help me out.
    Thank you very much for your help!
    Newman

  • How to set render true or false in java class

    Use case:
    i have a page in which i have one inputListOfValues attributes and two LOV .initial the LOV render attribute value is false .it means it show only one attribute in run time .inputListOfValues is content two value .suppose if first value A then the first LOV have to show and is it value is B then Second LOV have to show .i bind my LOV to class .but i do not know how to set render attribute at java class.

    <af:inputListOfValues label="Branch Name"
    popupTitle="Search and Result Dialog"
    id="ilov1"
    model="#{pageFlowScope.organizationLOV.param['bindings.Organization'].listOfValuesModel}"
    converter="#{pageFlowScope.organizationLOV.param['bindings.Organization'].convert['latinDesc']}"
    valueChangeListener="#{viewScope.salaryBenefitsReportForm.branchChange}"
    binding="#{viewScope.salaryBenefitsReportForm.branchName}"
    rendered="true" visible="false"/>
    <af:inputListOfValues label="Department Name"
    popupTitle="Search and Result Dialog"
    id="ilov2"
    model="#{pageFlowScope.objectLOV.param['bindings.Department'].listOfValuesModel}"
    converter="#{pageFlowScope.objectLOV.param['bindings.Department'].convert['latinDesc']}"
    valueChangeListener="#{viewScope.salaryBenefitsReportForm.departmentChange}"
    binding="#{viewScope.salaryBenefitsReportForm.departmentName}"
    rendered="true" visible="false"/>
    this is code in jsff .
    and class code are following
    public void reportBy(ValueChangeEvent valueChangeEvent) {
    String value=(String)valueChangeEvent.getNewValue();
    System.out.println(value);
    if(value.equals("Branch")){
    branchName.setVisible(true);
    departmentName.setVisible(false);
    AdfFacesContext.getCurrentInstance().addPartialTarget(branchName);
    AdfFacesContext.getCurrentInstance().addPartialTarget(departmentName);
    if(value.equals("Department")){
    departmentName.setVisible(true);
    branchName.setVisible(false);
    AdfFacesContext.getCurrentInstance().addPartialTarget(departmentName);
    AdfFacesContext.getCurrentInstance().addPartialTarget(branchName);
    }

  • How to launch a new JVM from a java class?

    I want to update a runing java applicaton. Before updating it, I have to shut down this application and open a new JVM (launch another java class with main method inside another JVM). Then update this application. After updating, restart this application. How to do it?? Thanks. Gary

    Hi!
    I'm using an applet to upload a library in the ext directory and then opening another applet that uses that library...
    If I manually upload the library the second applet works
    but if I try to load it at runtime with the first applet the file is saved correctly but the second applet doesn,t work :((
    the second applet works only if I close the browser and open it again...:((
    I need to reaload the JVM at runtime or maybe opening a new one...
    can anyone help me?
    please reply me if you found anything similar,
    ciao!
    fabibu

  • How to add XML Header tag to XML output from XI?

    Hi ,
    My requirement is I need to genarate the XML according to client requirements.
    I am able to genareate the XML with  <?xml version="1.0" encoding="UTF-8" ?>  as Header but client requiremetn is like this
    <?xml version="1.0" encoding="UTF-8" ?>
    <?Label MEXICO|PROFILE|2033169|SUCCESS?>
    and hear MEXICO and 2033169 will change dynamically for every xml genaration. How it make as dynamical and how can I achive this.?
    Plz guid me...
    Thanks
    Krishna

    You can refer to the code provided in this thread XML Tag Issue: Need extra Line with Xml RooTag and Convert the IDOC XML file into single string? . Java mapping would do these steps -
    a) Convert the incoming xml into string.
    b) Modify it with some string function as per requirement.
    c) Convert the string back to xml.
    For more understanding about Java mapping, go through links provided in the thread java mapping .
    Regards,
    Sunil Chandra

  • How to convert xml file to xsl using java

    Hi all,
    I have an XML file with which i need to convert(transform) it to an xsl file using java.
    I am new to converting xml file to xslt.Please send me if u have code .
    Thanks in advance
    regards
    Ram

    You seem to be asking the wrong question. An XSL file can be used to transform an XML file, but transforming an XML into an XSL does not make sense. The API for running XSL transforms on the Java platform is described here:
    http://java.sun.com/javase/6/docs/api/javax/xml/transform/package-summary.html

Maybe you are looking for

  • Infoset Creation on Cubes/DSO, which is better?

    Hi all, Creation of infoset on cubes is better or creation on DSO's is better with respect to  query performance? I would like to use infoset on DSO(created based on view EKBE) and 0FIAP_O03. I am worried of the query performance. Please suggest. Pra

  • EFS, password change denies access to encrypted data

    Hi, Has anyone had the issue with admin changing users password in Console One resulting in users not being able to access their encrypted data. Laptop users are using EFS to encrypt their data. These users have WinXPPro SP2 and we are running ZfD 6.

  • Printing date in the actual picture?

    Hi, I have iPhoto on two machines. One older and one newer. However, I cannot figure out how to save an image with the date -in- the image. My wife wants to print photos that included the date taken on the picture. Is there a way I can do this in iPh

  • BPM messages stuck In Process - never get sent

    Hi all, We have had a number of BPM processes running successfully in our XI 3.0 DEV SP17 system for weeks now but suddenly, none are now working. Our BPMs wait a specified amount of time before creating a bundled outbound message. In SXMB_MONI, the

  • How to use inline style for hover, visited

    I am trying to use inline styles for a hover effect or a visited. I know how to do it using a style sheet but not inline. Is it possible to do this?