Results 1 to 1 of 1
  1. #1
    Join Date
    Jan 2013
    Rep Power

    Default How to get XML attributes in Java and generate JSON?

    I have the following XML code:
    Java Code:
    <?xml version="1.0" encoding="UTF-8"?>
      <bpmn2:process id="defaultPackage.NewProcess2" >
        <bpmn2:startEvent id="StartEvent_1" name="StartProcess">
        <bpmn2:userTask id="UserTask_1" name="User Task 1">
      <bpmndi:BPMNDiagram id="BPMNDiagram_1">
        <bpmndi:BPMNPlane id="BPMNPlane_Process_1" bpmnElement="defaultPackage.NewProcess2">
          <bpmndi:BPMNShape id="BPMNShape_StartEvent_1" bpmnElement="StartEvent_1">
            <dc:Bounds height="36.0" width="36.0" x="60.0" y="210.0"/>
          <bpmndi:BPMNShape id="BPMNShape_UserTask_1" bpmnElement="UserTask_1">
            <dc:Bounds height="50.0" width="110.0" x="165.0" y="205.0"/>
    For the node <bpmn2:userTask> which is defined inside the <bpmn2:process> </bpmn2:process> tags, I want to get its coordinates, which are defined under
    Java Code:
    <bpmndi:BPMNShape id="BPMNShape_UserTask_1" bpmnElement="UserTask_1">
            <dc:Bounds height="50.0" width="110.0" x="165.0" y="205.0"/>
    inside <bpmndi:BPMNDiagram></bpmndi:BPMNDiagram>.

    I wrote the following code :
    Java Code:
    ArrayList<String> bpmnElements = getElementAttributes("bpmndi:BPMNShape", "bpmnElement");
    					for (int j = 0; j < bpmnElements.size(); j++)
    						String bpmnElement = bpmnElements.get(j);
                        	  ArrayList<String> idTask = getIds("bpmn2:task");
                        	  for(int l=0; l<idTask.size(); l++){
                        		  if(idTask.get(l).equals(bpmnElement)) //becouse the id attribute of bpmn2:userTask is equal to    
                                                           // bpmnElement attribute of    bpmndi:BPMNShape node
                        			  ArrayList<String> Xs = getElementAttributes ("dc:Bounds" , "x");
    where getElementsAttributes(gets all the attributes of the specified element of a specific node) and getIds(gets the id of the specified node) are two methods I built before and are completely functional , but I don't get anything in the output ...
    Last edited by blertadhimitri; 12-02-2013 at 05:26 PM.

Similar Threads

  1. Using JSON object in java
    By slider57 in forum New To Java
    Replies: 2
    Last Post: 07-22-2013, 08:14 PM
  2. could not convert the xml to json using java
    By cgk_js in forum Advanced Java
    Replies: 0
    Last Post: 11-30-2012, 10:31 AM
  3. class attributes vs instance attributes in web apps
    By rdangelo in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 06-26-2012, 12:39 PM
  4. JSON Lib: json-lib-1.0-jdk13.jar
    By Raghuraman K in forum Advanced Java
    Replies: 3
    Last Post: 05-13-2010, 10:00 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts