on 10-29-2005 12:05 AM
Hi,
In Web Dynpro,I have a scenario where i have to generate reports. For this, I enter the "Customer number", "Date" & "Item No" in 'Generate report' page and hit the "submit" button. These details are sent as XML to XI which interacts with the ABAP R/3 system, performs the search and returns the search results as an XML
Now, I want to display search results contained in this XML by populating it in a table.
From, the point where the XML is returned by XI, could you please tell me the step by step process to populate this XML in a table. Please include code, if any.
Kindly help.
Im working on EP using WebDynPro. I have the following XML which is returned by XI. This is just an example, the number items can vary, from 1 to any number.
<nsOrderDisplay:MT_Order_Display_Response xmlns:nsOrderDisplay="http://www.xxxx.com/xxx/POC">
<Result>
<CustomerNumber>111</CustomerNumber>
<ItemNumber>001</ItemNumber>
<Material>RAM</Material>
<OrderDate>2005-11-03</OrderDate>
</Result>
<Result>
<CustomerNumber>112</CustomerNumber>
<ItemNumber>002</ItemNumber>
<Material>HDD</Material>
<OrderDate>2005-11-04</OrderDate>
</Result>
<Result>
<CustomerNumber>113</CustomerNumber>
<ItemNumber>003</ItemNumber>
<Material>CDR</Material>
<OrderDate>2005-11-04</OrderDate>
</Result>
<Result>
<CustomerNumber>114</CustomerNumber>
<ItemNumber>004</ItemNumber>
<Material>Mouse</Material>
<OrderDate>2005-11-04</OrderDate>
</Result>
</nsOrder:MT_Order_Display_Response>
Can someone tell me how to populate this return XML into a table?
I want the entire code and the full steps involved in dynamically populating this kind of XML into a table. Please help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Sandeep,
Create context node with following strucure:
<i>
result
-CustomerNumber
-ItemNumber
-Material
-OrderDate</i>
Create data handler:
public class XIDataHandler extends DefaultHandler {
private String lastAttribute;
private IWDNodeElement newElement;
public void startElement(String namespaceURI, String localName, String rawName, Attributes atts) {
if ("Result".equals(localName)) {
newElement = wdContext.createResultElement();
wdContext.nodeResult().addElement(newElement);
} else {
if(null!=newElement)
{
lastAttribute = localName.trim();
}
}
}
public void endElement(String namespaceURI, String localName, String rawName) {
if ("Result".equals(localName)) {
newElement = null;
lastAttribute = null;
}
}
public void characters(char[] data, int off, int length) {
if(null!=newElement && null!=lastAttribute) {
final String value = new String(data, off, length).trim();
if(!"".equals(value)) {
newElement.setAttributeValue(lastAttribute, value);
}
}
}
}
And parse XML in appropriate place within your application:
try {
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
//Loading XML from string (XI_DOCUMENT), change if source differs
StringReader sr = new StringReader(XI_DOCUMENT.trim());
InputSource is = new InputSource(sr);
parser.parse(is, new XIDataHandler());
} catch (Exception e) {
final StringWriter sw = new StringWriter();
final PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
wdComponentAPI.getMessageManager().reportException(sw.toString(), true);
}
Create table and table columns and map your context to it.
Best regards, Maksim rashchynski.
Hi Sandeep,
You can use SAX/DOM parsers for parsing the XML and you can populate the Context in webdynpro which will be the Datasource for the Table.
1. Parse the XML and get the data in a collection.
2. Iterate through collection and populate the ValueNode in WebDynpro
3. Bind the valueNode to the table UIElement.
Regards, Anilkumar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.