cancel
Showing results for 
Search instead for 
Did you mean: 

How to remove element namespaces in XML file using DOM or SAX?

Former Member
0 Kudos

Hi Guys,

I developed a JAVA mapping in XI to add name spaces for XML file, after mapping,name spaces xmlns="http://www.mro.com/mx/integration" and xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" were added correctly, but for some nodes, such as <Header> and <Content>, a name space xmlns="" was added automatically.Please check below files to compare.

It looks like be added automatically by XI. I didn't process anything for these nodes in JAVA program.

Now the issue is, how can I remove these redundant namespaces? Such as xmlns="".

Can I remove them using DOM or SAX in JAVA Mapping?

Thanks in advance.

====>Original XML file

<?xml version="1.0" encoding="UTF-8"?>

<LLYLPPInterface language="EN">

<Header>

<SenderID>GBIP</SenderID>

<CreationDateTime>2008-02-13T22:49:34-05:00</CreationDateTime>

<RecipientID/>

<MessageID/>

</Header>

<Content>

<LLY-LPP>

<INVOICE>

<INVOICELINE>

<PONUM>4780000008</PONUM>

<POLINENUM>1</POLINENUM>

<INVOICEQTY>1</INVOICEQTY>

<LOADEDCOST>68</LOADEDCOST>

</INVOICELINE>

</INVOICE>

</LLY-LPP>

</Content>

</LLYLPPInterface>

===>Target XML file after JAVA mapping

<?xml version="1.0" encoding="utf-8"?>

<LLYLPPInterface language="EN" xmlns="http://www.mro.com/mx/integration" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<Header xmlns="">

<SenderID>GBIP</SenderID>

<CreationDateTime>2008-02-13T23:11:55-05:00</CreationDateTime>

<RecipientID/>

<MessageID/>

</Header>

<Content xmlns="">

<LLY-LPP>

<INVOICE>

<INVOICELINE>

<PONUM>4780000008</PONUM>

<POLINENUM>0</POLINENUM>

<INVOICEQTY>1</INVOICEQTY>

<LOADEDCOST>68</LOADEDCOST>

</INVOICELINE>

</INVOICE>

</LLY-LPP>

</Content>

</LLYLPPInterface>

Edited by: Eddie Zhang on Feb 14, 2008 9:22 AM

Edited by: Eddie Zhang on Feb 14, 2008 9:24 AM

Accepted Solutions (0)

Answers (2)

Answers (2)

stefan_grube
Active Contributor
0 Kudos

The namespace xmlns="" is not redundent. The message would be different without this.

The XI does not add anything to a message, so this comes from your Java mapping.

If you use DOM parser, check your code carefully. Maybe you use SAX parser instead.

Regards

Stefan

milan_10
Participant
0 Kudos

Try to check this: /people/stefan.grube/blog/2007/02/02/remove-namespace-prefix-or-change-xml-encoding-with-the-xmlanonymizerbean

Former Member
0 Kudos

Hi Milan,

Thanks for your replay.

Actually when I used module XMLAnonymizerBean to convert namespaces, the header of XML, such as <?xml version="1.0" encoding="UTF-8"?> was converted to format <?xml version='1.0' encoding='UTF-8'?>, quote was converted to single quote. Although I set parameter anonymizer.quote = ", it still didn't work, single quote appeared instead of quote.

I'm not sure why this happened. Can anyone help to clarify this?

Thanks

Edited by: Eddie Zhang on Feb 15, 2008 2:11 AM

stefan_grube
Active Contributor
0 Kudos

> Actually when I used module XMLAnonymizerBean to convert namespaces, the header of XML, such as <?xml version="1.0" encoding="UTF-8"?> was converted to format <?xml version='1.0' encoding='UTF-8'?>, quote was converted to single quote. Although I set parameter anonymizer.quote = ", it still didn't work, single quote appeared instead of quote.

The XML declaration is not influenced by the parameter. You cannot change this.

Regards

Stefan