cancel
Showing results for 
Search instead for 
Did you mean: 

XML parsing in Operation Mapping

former_member200339
Participant
0 Kudos

Dear All,

I have developed a Java Mapping program where I am parsing an incoming IDOC using the DOM parser. I found that the program works well for some message while it does not work for other. It does not throw any error but it does not return the correct data also.

As for example,

value of the field returned for correct parsing = 10976342

value of the field returned for in-correct parsing = #text

I also found that for some IDOC which is successfull and later when I download it from sxi_monitor and edit it in notepad - changing a value of a field from 100 to 200 and send the same message from  "Send Test Message", it gives wrong output.

Your suggestion is welcome.

Thanks and Regards,

Rana Brata De

Accepted Solutions (1)

Accepted Solutions (1)

MichalKrawczyk
Active Contributor
0 Kudos

Hi,

did you debug the mapping in NWDS to see where the issue is ?

as it's probably not related to PI but to your coding,

Regards,

Michal Krawczyk

former_member200339
Participant
0 Kudos

Hello Michal,

The code is very simple : within a try-catch block I am writing

 

DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance();
dbfactory.setNamespaceAware(true);
DocumentBuilder dbuilder = dbfactory.newDocumentBuilder();
Document doc = dbuilder.parse(in);
doc.getDocumentElement().normalize();

NodeList E1EDK02List  = doc.getElementsByTagName("E1EDK02");
for(int i=0;i<E1EDK02List.getLength();i++)
{
String node_name = E1EDK02List.item(i).getFirstChild().getNodeName());
}

this line sometimes returns the node_name and sometime the #test

E1EDK02List.item(i).getFirstChild().getNodeName());

iaki_vila
Active Contributor
0 Kudos

Hi Rana,

But don't  you want to get the value?

To get the value, try this

String value = E1EDK02List.item(i).getFirstChild().getTextContent();

Regards.

anupam_ghosh2
Active Contributor
0 Kudos

Hi Rana Brata,

                          Changing your code a little bit

{

DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance();

dbfactory.setNamespaceAware(true);

DocumentBuilder dbuilder = dbfactory.newDocumentBuilder();

Document doc = dbuilder.parse(in);

doc.getDocumentElement().normalize();

Node temp;

NodeList E1EDK02List  = doc.getElementsByTagName("E1EDK02");

for(int i=0;i<E1EDK02List.getLength();i++)

{

   temp=E1EDK02List.item(i);

    while(temp!=null && temp.getNodeType() != Node.ELEMENT_NODE){

          temp=temp.getNextSibling();

   }

   if(temp!=null && temp.getNodeType() == Node.ELEMENT_NODE)

   {

           String node_name = temp.getNodeName());

   }

}

Try this let's hope error disappears.

Regards

Anupam

Message was edited by: Anupam Ghosh

former_member200339
Participant
0 Kudos

Hi Anupam,

Your code has helped me a lot to solve the problem.

Thanks and Regards,

Rana

anupam_ghosh2
Active Contributor
0 Kudos

Hi Rana,

                I am modifying the code a little bit

Please check if this works perfect.

{

    DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance(); 

    dbfactory.setNamespaceAware(true); 

    DocumentBuilder dbuilder = dbfactory.newDocumentBuilder(); 

    Document doc = dbuilder.parse(in); 

    doc.getDocumentElement().normalize(); 

     

    Node temp; 

     

    NodeList E1EDK02List  = doc.getElementsByTagName("E1EDK02"); 

    for(int i=0;i<E1EDK02List.getLength();i++) 

    { 

     

       temp=E1EDK02List.item(i).getFirstChild(); 

     

        while(temp!=null && temp.getNodeType() != Node.ELEMENT_NODE){ 

     

              temp=temp.getNextSibling(); 

       } 

       if(temp!=null && temp.getNodeType() == Node.ELEMENT_NODE) 

       { 

               String node_name = temp.getNodeName()); 

       } 

    } 

Regards

Anupam

Answers (0)