Structure of xml
How do I format the structure of xml
from:
<root><news><title>title
text</title><body>body
text</body></news></root>
to:
<root>
<news>
<title>title text</title>
<body>body text</body>
</news>
</root>
//code
var news_xml:XML = new XML();
news_xml.ignoreWhite = true;
AddNewsEntry();
function AddNewsEntry() {
var newsRoot:XMLNode = news_xml.createElement("root");
var newsNode:XMLNode = news_xml.createElement("news");
var titleNode:XMLNode = news_xml.createElement("title");
var bodyNode:XMLNode = news_xml.createElement("body");
var titleText:XMLNode = news_xml.createTextNode("title
text");
var bodyText:XMLNode = news_xml.createTextNode("body text");
news_xml.appendChild(newsRoot);
newsNode.appendChild(titleNode);
newsNode.appendChild(bodyNode);
newsRoot.appendChild(newsNode);
titleNode.appendChild(titleText);
bodyNode.appendChild(bodyText);
trace(news_xml);
Try the attached code. It will convert the XML into a string
that should be formatted correctly.
Similar Messages
-
Can we express batch relationship structure in XML in the database table
Hi
please help me ..
i have a batch XML batch structure ...can we express batch relationship structure in XML in tha database table?
yes..then how?
Thanks
Amu
Edited by: amu_2007 on Mar 25, 2010 6:57 PM
Edited by: amu_2007 on Mar 25, 2010 7:03 PMBut what is the problem with the initial solution given that split the XML into the data?
I mean you could do something like this?
SQL> create table batch (customer VARCHAR2(10)
2 ,cust_name VARCHAR2(10)
3 ,cust_type VARCHAR2(10)
4 )
5 /
Table created.
SQL>
SQL> create table section (customer VARCHAR2(10)
2 ,sect_name VARCHAR2(10)
3 ,sect_depend VARCHAR2(10)
4 )
5 /
Table created.
SQL> create table job_sections (customer VARCHAR2(10)
2 ,sect_name VARCHAR2(10)
3 ,job_sect_name VARCHAR2(10)
4 ,job_sect_depend VARCHAR2(10)
5 )
6 /
Table created.
SQL> create table job (customer VARCHAR2(10)
2 ,sect_name VARCHAR2(10)
3 ,job_sect_name VARCHAR2(10)
4 ,job_type VARCHAR2(10)
5 ,job_sub_type VARCHAR2(10)
6 ,job_depend VARCHAR2(10)
7 )
8 /
Table created.
SQL>
SQL>
SQL> insert all
2 when batch_rn = 1 then
3 into batch (customer, cust_name, cust_type) values (customer, cust_name, cust_type)
4 when section_rn = 1 then
5 into section (customer, sect_name, sect_depend) values (customer, sect_name, sect_dependency)
6 when job_sections_rn = 1 then
7 into job_sections (customer, sect_name, job_sect_name, job_sect_depend) values (customer, sect_name, job_sect_name, job_sect_dependency)
8 when 1=1 then
9 into job (customer, sect_name, job_sect_name, job_type, job_sub_type, job_depend) values (customer, sect_name, job_sect_name, job_type, jo
10 --
11 WITH t as (select XMLTYPE('
12 <BATCH customer="ABC" name="ABC1" type="ABC_TYPE">
13 <BATCH_SECTIONS>
14 <SECTION name="X" dependency="NULL">
15 <JOB_SECTIONS name="JOB1" dependency="NULL" >
16 <JOBS>
17 <JOB type="X" sub_type="xx" dependency="NULL" />
18 <JOB type="X" sub_type="yy" dependency="NULL" />
19 <JOB type="X" sub_type="zz" dependency="NULL" />
20 </JOBS>
21 </JOB_SECTIONS>
22 </SECTION>
23 <SECTION name="Y" dependency="X">
24 <JOB_SECTIONS name="JOB2" dependency="X" >
25 <JOBS>
26 <JOB type="Y" sub_type="xx" dependency="X" />
27 <JOB type="Y" sub_type="yy" dependency="X" />
28 <JOB type="Y" sub_type="zz" dependency="X" />
29 </JOBS>
30 </JOB_SECTIONS>
31 </SECTION>
32 <SECTION name="Z" dependency="Y">
33 <JOB_SECTIONS name="JOB3" dependency="NULL" >
34 <JOBS>
35 <JOB type="....." sub_type="...." dependency="NULL" />
36 </JOBS>
37 </JOB_SECTIONS>
38 <JOB_SECTIONS name="JOB4" dependency="NULL">
39 <JOBS>
40 <JOB type="...." sub_type="...." dependency="NULL" />
41 </JOBS>
42 </JOB_SECTIONS>
43 </SECTION>
44 </BATCH_SECTIONS>
45 </BATCH>
46 ') as xml from dual)
47 --
48 -- END OF TEST DATA
49 --
50 ,flat as (select a.customer, a.cust_name, a.cust_type
51 ,b.sect_name, NULLIF(b.sect_dependency,'NULL') as sect_dependency
52 ,c.job_sect_name, NULLIF(c.job_sect_dependency,'NULL') as job_sect_dependency
53 ,d.job_type, d.job_sub_type, NULLIF(d.job_dependency,'NULL') as job_dependency
54 from t
55 ,XMLTABLE('/BATCH'
56 PASSING t.xml
57 COLUMNS customer VARCHAR2(10) PATH '/BATCH/@customer'
58 ,cust_name VARCHAR2(10) PATH '/BATCH/@name'
59 ,cust_type VARCHAR2(10) PATH '/BATCH/@type'
60 ,bat_sections XMLTYPE PATH '/BATCH/BATCH_SECTIONS'
61 ) a
62 ,XMLTABLE('/BATCH_SECTIONS/SECTION'
63 PASSING a.bat_sections
64 COLUMNS sect_name VARCHAR2(10) PATH '/SECTION/@name'
65 ,sect_dependency VARCHAR2(10) PATH '/SECTION/@dependency'
66 ,section XMLTYPE PATH '/SECTION'
67 ) b
68 ,XMLTABLE('/SECTION/JOB_SECTIONS'
69 PASSING b.section
70 COLUMNS job_sect_name VARCHAR2(10) PATH '/JOB_SECTIONS/@name'
71 ,job_sect_dependency VARCHAR2(10) PATH '/JOB_SECTIONS/@dependency'
72 ,job_sections XMLTYPE PATH '/JOB_SECTIONS'
73 ) c
74 ,XMLTABLE('/JOB_SECTIONS/JOBS/JOB'
75 PASSING c.job_sections
76 COLUMNS job_type VARCHAR2(10) PATH '/JOB/@type'
77 ,job_sub_type VARCHAR2(10) PATH '/JOB/@sub_type'
78 ,job_dependency VARCHAR2(10) PATH '/JOB/@dependency'
79 ) d
80 )
81 --
82 select customer, cust_name, cust_type, sect_name, sect_dependency, job_sect_name, job_sect_dependency, job_type, job_sub_type, job_dependency
83 ,row_number() over (partition by customer order by 1) as batch_rn
84 ,row_number() over (partition by customer, sect_name order by 1) as section_rn
85 ,row_number() over (partition by customer, sect_name, job_sect_name order by 1) as job_sections_rn
86 from flat
87 /
16 rows created.
SQL> select * from batch;
CUSTOMER CUST_NAME CUST_TYPE
ABC ABC1 ABC_TYPE
SQL> select * from section;
CUSTOMER SECT_NAME SECT_DEPEN
ABC X
ABC Y X
ABC Z Y
SQL> select * from job_sections;
CUSTOMER SECT_NAME JOB_SECT_N JOB_SECT_D
ABC X JOB1
ABC Y JOB2 X
ABC Z JOB3
ABC Z JOB4
SQL> select * from job;
CUSTOMER SECT_NAME JOB_SECT_N JOB_TYPE JOB_SUB_TY JOB_DEPEND
ABC X JOB1 X xx
ABC X JOB1 X yy
ABC X JOB1 X zz
ABC Y JOB2 Y xx X
ABC Y JOB2 Y yy X
ABC Y JOB2 Y zz X
ABC Z JOB3 ..... ....
ABC Z JOB4 .... ....
8 rows selected.
SQL>But it would depend what you are actually after in terms of primary keys, and table relationships etc.
Let me put this simply for you...
h1. IF YOU DON'T DEMONSTRATE TO US WHAT OUTPUT YOU REQUIRE, WE CAN'T GIVE YOU AN ANSWER -
Easy way how to convert deep structure to XML
Hi,
is there any easy way how to convert a complex deep structure to XML. I have XSLT transformation ready for using, but when I look on examples on using CALL TRANSFORMATION, I am finding only examples for internal tables.
Something like this CALL TRANSFORMATION SOURCE tab = sometab[].
Instead of this I need to convert a comlex deep structure.
Any help is appreciated.
Thanks.
MarianHi,
is there any easy way how to convert a complex deep structure to XML. I have XSLT transformation ready for using, but when I look on examples on using CALL TRANSFORMATION, I am finding only examples for internal tables.
Something like this CALL TRANSFORMATION SOURCE tab = sometab[].
Instead of this I need to convert a comlex deep structure.
Any help is appreciated.
Thanks.
Marian -
How to see the IDOC structure in XML format
Hi, I am ver new to MII. I configured connection between SAPand SAP MII and IDOC is triggering in SAP MII. I can see the idoc triggered in Message monitor.
Now my query is how to see the IDOC structure in XML format? I written a transaction where I am assigning transaction.xml to my Local.xml and trying to display with message action block. When I display the message I am getting message as below
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
There is no data in the xml, but in SAP side i seen data and segment which sent to MII as a IDOC. Please help me how to resolve this issue.Hi, Thanks for quick response.
In Message monitor I seen the IDOC list after executing POIT transaction code in SAP.
But the display button is disabled always in message monitor screen. I want to take this IDOC and save it in my SQL database. So I want to see this IDOC structure in XML format. Where i can see this structure? -
How to structure an XML doc using schema?
Hi there,
I have an XML file with a grouped <employee> tags like,
<employee>
<employeename>John</employeename>
<employeename>Dave</employeename>
</employee>
I want to structure above xml file to be like this
<employee>
<employeename>John</employeename>
</employee>
<employee>
<employeename>Dave</employeename>
</employee>
Can I do that in a XML schema (.xsd file)? If I can, how do I do that?
Thanks,
ChandiHi Dave,
Thanks for your response.
I create this XML from .xsd files using a tool (MapForce by Altova which allows me to do the mappings between relational database table columns and elements in the .xsd file, and it creates Java code for me), the data is read from a database to compose this XML file.
Everything works fine with this XML file, I just want to change the structure of the XML file when it composes it, I was wondering if I could do that by changing the existing .xsd file?
Its not easy to use XSLT, I�m dealing with over 600 hierarchical elements with over 15 .xsd files.
So, what are my options?
All I want to know is, what should I change in the .xsd in order to compose this XML in the structure that I want.
It groups all the employee names (<employeename> tag) under one <employee> tag, instead I want to have individual <employee> tags for each and every <employeename> tags (<employee> tag around <employeename> tag for each and every employee)
Is it possible at all?
Thanks,
Chandi -
XML Structure in XML Component
Hi,
I'm trying to build an XML component in Portal 9.0.2.
What I need to know is the structure of the XML generated by SQL placed inside the <ORACLE> tags so I can parse it with the XSL style sheet.
All the examples I've seen (about 2) show the sql coming out in one lump in a table, but I want to be able to parse individual columns from the SQL. All I seem to get is a default presentation of the data.
Any Ideas ?Hi,
This is not possible currently. There is an enhancement filed for this.
Thanks,
Sharmila -
Source structure of XML file as different from Message type?
Hi,
We are picking an xml file from the FTP server of the client.
We have source message type 'MT_Invoice' with data type as 'DT_Invoice'.
When we open the message mapping test tab, the source structure is as shown below.
<ns0:MT_Invoice xmlns:ns0="urn:maxxium:nordic:invoice:inbound">
<Invoices>
<Invoice>
</Invoice>
</Invoices>
</MT_Invoice>
My question is "What should be the structure of the XML file that the client is depositing on to the FTP server?".
Should it start with the tag 'MT_Invoice' with the namespace or should it simply start from <Invoices> tag.
I have tried various combinations for the source xml structure. But all are failing.
(This is evident from the fact that the mapping is failing. That's why I have given the structure from the source structure of the message mapping tab.)
Kindly help.
Thanks,
John>
john j wrote:
> Hi,
>
> We are picking an xml file from the FTP server of the client.
>
> We have source message type 'MT_Invoice' with data type as 'DT_Invoice'.
>
> When we open the message mapping test tab, the source structure is as shown below.
>
> <ns0:MT_Invoice xmlns:ns0="urn:maxxium:nordic:invoice:inbound">
> <Invoices>
> <Invoice>
> .
> .
> .
> .
> </Invoice>
> </Invoices>
> </MT_Invoice>
>
> My question is "What should be the structure of the XML file that the client is depositing on to the FTP server?".
>
> Should it start with the tag 'MT_Invoice' with the namespace or should it simply start from <Invoices> tag.
>
> I have tried various combinations for the source xml structure. But all are failing.
>
> (This is evident from the fact that the mapping is failing. That's why I have given the structure from the source structure of the message mapping tab.)
>
> Kindly help.
>
> Thanks,
> John
you are picking an XML file. So you should create the MT which would represent exactly the XML format of the source file.
So ideally if your file starts with <invoice>, then name your MT as invoice -
Automatic creation of KM folder structure from xml pattern
Hi all,
is it possible to create a KM folder structure automaticly, following the tree structure of an xml document?
For example:
an xml-document with following content:
<item id=1 level=0>abc</item>
<item id=2 level=1>aaa</item>
<item id=3 level=1>bbb</item>
<item id=4 level=2>ccc</item>
<item id=5 level=0>def</item>
I'd like to create a KM folder structure like this:
- abc
---aaa
---bbb
ccc
- def
Does anyone have any idea to implement this scenario in KM?
Much obliged!
SteffiNot currently - well at least not easily - there is always the programatic approach.
I would suggest you can create an FSDB repository - this means you can then create your structure in the file system using standard desktop tools.
After that you could do a mass copy back into the db based KM repository if you so wished.
For your downstream systems you could always ICE the data across meaning you dont have to create everything again.
Haydn -
Deep structure to XML and saving in SAP tables
Hi all,
ich habe filled an internal table (deep strucure) with mutiple fields. Most of these fields are defined as structure.
Example: 1st field ist document number, 2nd field is defined as TLINETAB, 3rd field ist another document number, 4th field is filled with node table of a column tree, 5th field ist filled with the item table of a column tree and in the last field I save the ALV properties of buttons, defined with lvc_t_styl.
So my problem is that I want to save all these contents in database tables and restore in my application when the user ist starting again. How can I save this and how have I define the database table to save? I thought 1st field is e.g. document number, 2nd is a counter and 3rd field is a CHAR field. Then the internal table will be converted (XML?) and the result will be append to my table line by line.
Thanks for help and regards
MichaelHi,
This looks like a perfect use for the Shared Objects functionality, introduced in SAP Web AS 6.40. See some [SAP documentation|http://help.sap.com/saphelp_nw70/helpdata/en/14/dafc3e9d3b6927e10000000a114084/frameset.htm] for this feature and an [example of use|http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/900e3d9d-559e-2910-9dae-b132157a220f?QuickLink=index&overridelayout=true].
Hope this helps,
Grzegorz -
Structure of XML that can be interpreted by KM?
Hi,
My requirement is as follows - I need to bring in the documents stored in an external repository(Lotus Domino server) into KM repository thereby avoiding the external repository totally. This is how I am trying to approach - to convert all documents in the external repository into XML documents that is understandable by KM. Now, what I would like to know is the structure of the XML. Is there a specific XML structure that KM can read & hence store the documents accordingly in its repository?
Any help will be greatly appreciated.
Regards,
M.SubathraAny thoughts on this?
-
I've been looking for a solution to this problem for some time now, and still no luck.
I'm going to point out first that I do NOT know the exact structure of the Tree Model. This is because the user can manipulate the tree as they wish. My problem comes when I want to save/load this tree structure, I thought that XML seems like the ideal choice.
My problem is that because I don't know the structure of the Tree Model, I'm not sure how to loop through every node in the Tree Model and add it to my XML Document.
People have suggested looping through the Tree Models children, except that wouldn't return the many other nodes that may be in the Tree Model.
If I haven't explained it very well, or you need to know any extra info just reply asking.
Hope someone out there can give me a hand, cheers!You could get the root node as DefaultMutableTreeNode:
TreeModel treeMdl = jTree.getModel();
DefaultMutableTreeNode root = (DefaultMutableTreeNode) treeMdl.getRoot(); and traverse the tree from there.
DefaultMutableTreeNode class has some related methods:
public Enumeration preorderEnumeration()
public Enumeration postorderEnumeration()
public Enumeration breadthFirstEnumeration()
public Enumeration depthFirstEnumeration()
public int getChildCount()
public TreeNode getChildAt(int index) -
Hi,
I have a multilevel structure that looks like that :
a = structNew()
a.a.a.a = apple
a.a.a.b = banana
a.a.b.a = potato
a.b = beef
What would be the best way of converting that structure in an
XML document that would look like the following attached code ?
Any suggestion ? The structure isn't always 4-levels deep.
Sometimes it can be 3, 4, 8, 2...
I thought I would just loop recursively over my structure :
calling a method that would check if the item is a struct and if so
create a new XML node inside the XML node being processed or else
just put the value in node currently being open, then return the
result back to the calling method... and so on.
Is there any sort of code snippet that may convert a
multilevel structure to an XML document ? All examples I've found
so far only deals with one level.
Thanks in advance,
PatrickThanks, I already came accross that code but unfortunately it
does process only the first level of a structure :
form.author
form.book_title
form.nb_book_pages
And I needed :
form.author.firstname
form.author.lastname
form.book.title
form.book.pages
etc...
But I found a solution ! I did it through a recursive
function inside a CFC... I'll post the code soon, I don't have it
at hand right now.
Patrick -
IDOC --- XI -- HTTP (via a flat file structure, not XML)
I am working on a senario in which we need to send a third party payroll service provider our HR Master Data records (Message type HROT_UM). The manual method is to create a flat file from an IDOC and place the file in a shared directory, then upload the flat file by logging on to the web server. We would like to automate this process using XI.
Is it possible to send a flat file structure to a webserver using a HTTP receiver adapter? If not, can you provide a basic view of how to accomplish this task. Please note that FTP is not an option for us.
Any suggestions or recommendations would be greatly appreciated.hey
flat file over HTTP is not possible,it takes only XML.
have a look at the following thread
Send file through http
thanx
ahmad
PL:reward with points for helpful answers -
Hi,
is there an easy way to create a xml string based on a ddic structure?
Its a nested structure and I want to avoid to create all elements manually.
Perfect way would be that i could fill the structure with data and then transform this into a xml string.
for instance:
ls_test-header-name = 'tester'
ls_test-header-county = 'germany'
ls_test-item-material = '4711'
ls_test-item-pos = '1'
should be transformed to:
<?xml version="1.0"?>
<ls_test>
<header>
<name>tester</name>
<country>germany</country>
</header>
<item>
<material>4711</material>
<pos>1</pos>
</item>
</ls_test>
Thanks,
ChristophHi Christoph,
following link describes the xml transformation suggested above:
http://help.sap.com/saphelp_erp2005vp/helpdata/en/e3/7d4719ca581441b6841f1054ff1326/frameset.htm
and here is a small example
http://help.sap.com/saphelp_erp2005vp/helpdata/en/ae/101640a991c742e10000000a1550b0/frameset.htm
Hope this is helpful.
Regards
Bernd -
Help with ABAP Structure to XML - Simple Transformation
Hi guys,
I need help with a Simple Transformation. I am trying to convert a structure in ABAP to XML String but i ma getting short dumps...
Can any of you help.
Thanks in advance.
*& Report ZTESTXML
REPORT ZTESTXML.
class demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS main.
ENDCLASS.
CLASS demo IMPLEMENTATION.
method main.
data : begin of account,
partner type bu_partner,
primary(1),
update(3),
email(50),
memberid(4),
telephone(12),
fax(10),
dept(20),
end of account.
data : xmlstr type xstring.
account-partner = '12345'.
account-primary = 'N'.
account-update = 'Yes'.
account-email = 'zz at hotmail.com'.
account-memberid = '555'.
account-telephone = '123-448-6710'.
account-fax = '345-123-7899'.
account-dept = 'Info Systems'.
call TRANSFORMATION ztest_inttable
SOURCE account = 'account'
result XML xmlstr.
call FUNCTION 'DISPLAY_XML_STRING'
EXPORTING xml_string = xmlstr.
ENDMETHOD.
ENDCLASS.
start-of-SELECTION.
demo=>main( ).
Transformation
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="account"/>
<tt:template>
<IGT_CRM_AccountInfo>
<Account>
<tt:ref name=".account">
<tt:attribute name="Id" value-ref="PARTNER"/>
<tt:attribute name="Primary" value-ref="primary"/>
<tt:attribute name="Update" value-ref="update"/>
<Contact>
<tt:attribute name="EMail" value-ref="email"/>
<tt:attribute name="Member Id" value-ref="memberid"/>
</Contact>
<Communications>
<tt:attribute name="Telephone" value-ref="telephone"/>
<tt:attribute name="Fax" value-ref="fax"/>
</Communications>
<IGT>
<tt:attribute name="Department" value-ref="dept"/>
</IGT>
</tt:ref>
</Account>
</IGT_CRM_AccountInfo>
</tt:template>
</tt:transform>
Dump message
An exception occurred that is explained in detail below.
The exception, which is assigned to class 'CX_ST_REF_ACCESS', was not caught in
procedure "MAIN" "(METHOD)", nor was it propagated by a RAISING clause.
Since the caller of the procedure could not have anticipated that the
exception would occur, the current program is terminated.
The reason for the exception is:
The goal was to access variable "PARTNER". However, this access was not
possible.to convert abap itab or variable into xml string use ABAP key word call transformation.
call transformation (`ID`)
source output = itab[]
result xml xml_out.
where itab is your internal table or any abap variable.
xml_out is type string which will hold the resulting xml.
ID is the transformation program. if you wanto use your own transformation, use your XSLT or ST program there.
Raja
Maybe you are looking for
-
Does anyone know how to fix this it happens every few months or so, ive stopped getting video when i watch them on the internet i only get audio. I've tried the web plug in method thats on here but its not there anymore from the last time it broke an
-
Select key date of time-dependent hierarchy before select a hierarchy node
Hello experts! I have a Web Application which has a selection on 0ORGUNIT (organizational unit). The selection is on hierarchy nodes and the hierarchy is time-dependent. Because of the time-dependency I have to give a key date for the hierarchy. But
-
SAP Upgradation from 4.5B to ECC 6.0
Hi all, We need to upgrade from 4.5B to ECC 6.0. Gathered all the information abt. the 4.5 B system...Its on AIX using ORACLE. I want to know few more info. with your help. i have access to the system through GUI, but didnt have OS level access.. 1.)
-
When I export to epub, I get 2 TOCs
I'm putting together my first epub, and I'm following along a video on Lynda.com to do it (the video title is "InDesign CS5.5 to EPUB, Kindle, and iPad" by Anne-Marie Concepcion, although I am using ID CS6). It was going fine until the table of conte
-
What is the best program to do this?
Hola I'm trying to put some music into a website and I found this http://www.flashmusicstudio.com/ --sorry if I don't put it in a link-- ...I think it's awesome, but it doesn't work or I cannot make it work. If I put the finish file in the webpage th