How to remove xmlns from xml using java

Hi,
<DLList xmlns="http://www.test.com/integration/feed" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Weather>
<StateName>Karnataka</StateName>
<ForecastName>Bagalkote</ForecastName>
<Humidity>89.9</Humidity>
</Weather>
<Weather>
<StateName>Karnataka</StateName>
<ForecastName>Devengiri</ForecastName>
<Humidity>89.9</Humidity>
</Weather>
</DLList>
The above xml needs to be decomposed using xsu.I am facing a small problem because the xml has namespaces.
How to remove the namespace using java to get the below xml
Note:I am using XSLT for the transformation.The XSLT tag is not identifying the <DLList> tag with name space
<DLList>
<Weather>
<StateName>Karnataka</StateName>
<ForecastName>Bagalkote</ForecastName>
<Humidity>89.9</Humidity>
</Weather>
<Weather>
<StateName>Karnataka</StateName>
<ForecastName>Devengiri</ForecastName>
<Humidity>89.9</Humidity>
</Weather>
</DLList>
Please help.Let me know if any other information is required
Thanks

OK, here goes :
For the example, I'll use a TB_DISTRICT table with the following structure :
create table tb_district (
sr_no number(3),
district_name varchar2(100)
);loaded with data from this page :
http://india.gov.in/knowindia/districts/andhra1.php?stateid=KA
and this XML document (one additional record compared to the one you posted) :
<DLList xmlns="http://www.test.com/integration/feed" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Weather>
<StateName>Karnataka</StateName>
<ForecastName>Bagalkote</ForecastName>
<Humidity>89.9</Humidity>
</Weather>
<Weather>
<StateName>Karnataka</StateName>
<ForecastName>Devengiri</ForecastName>
<Humidity>89.9</Humidity>
</Weather>
<Weather>
<StateName>Karnataka</StateName>
<ForecastName>Dharwad</ForecastName>
<Humidity>70.1</Humidity>
</Weather>
</DLList>In order to access the XML, I'll also use this Oracle directory object :
create directory test_dir as 'D:\ORACLE\test';Final relational tables are :
create table BUSINESS_TABLE
  STATE         VARCHAR2(30),
  DISTRICT_NAME VARCHAR2(30),
  HUMIDITY      NUMBER
);and
create table REJECT_TABLE
  STATE         VARCHAR2(30),
  DISTRICT_NAME VARCHAR2(30),
  HUMIDITY      NUMBER,
  ERROR_MESSAGE VARCHAR2(500)
);With XMLTable function, we can easily break the XML into relational rows and columns ready to use for DML :
SQL> alter session set nls_numeric_characters=". ";
Session altered
SQL>
SQL> SELECT *
  2  FROM XMLTable(
  3    XMLNamespaces(default 'http://www.test.com/integration/feed'),
  4    '/DLList/Weather'
  5    passing xmltype(bfilename('TEST_DIR','test.xml'), nls_charset_id('CHAR_CS'))
  6    columns
  7      state         varchar2(30) path 'StateName'
  8    , district_name varchar2(30) path 'ForecastName'
  9    , humidity      number       path 'Humidity'
10  )
11  ;
STATE                          DISTRICT_NAME                    HUMIDITY
Karnataka                      Bagalkote                            89.9
Karnataka                      Devengiri                            89.9
Karnataka                      Dharwad                              70.1
Then with a multitable insert, we load both the business table and the reject table (if the district name does not exist in TB_DISTRICT) :
SQL> INSERT FIRST
  2    WHEN master_district_name IS NOT NULL
  3      THEN INTO business_table (state, district_name, humidity)
  4                VALUES (state, district_name, humidity)
  5    ELSE INTO reject_table (state, district_name, humidity, error_message)
  6              VALUES (state, district_name, humidity, 'Invalid district name')
  7  WITH xml_data AS (
  8    SELECT *
  9    FROM XMLTable(
10      XMLNamespaces(default 'http://www.test.com/integration/feed'),
11      '/DLList/Weather'
12      passing xmltype(bfilename('TEST_DIR','test.xml'), nls_charset_id('CHAR_CS'))
13      columns
14        state         varchar2(30) path 'StateName'
15      , district_name varchar2(30) path 'ForecastName'
16      , humidity      number       path 'Humidity'
17    )
18  )
19  SELECT x.*
20       , t.district_name as master_district_name
21  FROM xml_data x
22       LEFT OUTER JOIN tb_district t ON t.district_name = x.district_name
23  ;
3 rows inserted
SQL> select * from business_table;
STATE                          DISTRICT_NAME                    HUMIDITY
Karnataka                      Dharwad                              70.1
SQL> select * from reject_table;
STATE                          DISTRICT_NAME                    HUMIDITY ERROR_MESSAGE
Karnataka                      Bagalkote                            89.9 Invalid district name
Karnataka                      Devengiri                            89.9 Invalid district name

Similar Messages

  • How to remove Unicode from XML file

    I get following error when unmarshal xml:
    [java] org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0x15) was found in the element content of the document.
    Anyone know how to remove Unicode from xml file? Can I remove the unicode by rebuild the file?
    Thanks

    These sort of error usually occur when you're using a different character encoding to read the file than the one you wrote it with. Perhaps if you were to post the problem section of the file and/or the code that created it in the first place.

  • How to retrieve data from MDM using java API

    hi experts
    Please explain me the step by step procedure
    how to retrieve data from MDM using java API
    and please tell me what are the
    important classes and packages in MDM Java API
    thanks
    ramu

    Hi Ramchandra,
    You can refer to following links
    MDM Java API-pdf
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/2d18d355-0601-0010-fdbb-d8b143420f49
    webinr of java API
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/89243c32-0601-0010-559d-80d5b0884d67
    Following Fourm Threads will also help.
    Java API
    Java API
    Re: usage of  java API ,
    Matching Record
    Need Java API for Matching Record
    Thanks and Regards,
    Shruti.
    Edited by: Shruti Shah on Jul 16, 2008 12:35 PM

  • Remove element from xml using dom.

    i want to remove an element from an xml file using dom.
    i remove the element but the whole content of the file is also deleted.
    how can i rewrite the file.

    vij_ay wrote:
    subject :Remove element from xml,but if empty element in input file then output should be <tag></tag>, not like <tag.xml/>I assume you mean <tag/> but why do you want this? Any application that will not accept this valid XML construct is flawed and a bug report should be raised against it.

  • How to remove xmlns="" from the message

    some reason on the header node in the below message gets xmlns="" when the message is generated from BPEL.
    below is the output that generated. I want to remove xmlns="" from the message.
    <?xml version="1.0" ?><ProductMovementReport xmlns="urn:cidx:names:specification:ces:schema:all:4:0" Version="4.0">
    <Header xmlns="">
    <ThisDocumentIdentifier>
    <DocumentIdentifier>42519</DocumentIdentifier>
    </ThisDocumentIdentifier>
    <ThisDocumentDateTime>
    Can anybody help me please ?

    It's is missing my blog article :-)
    Here it is:
    <?xml version="1.0" encoding="UTF-8" ?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="comment()|processing-instruction()|/"><xsl:copy><xsl:apply-templates/></xsl:copy></xsl:template><xsl:template match="*"><xsl:element name="{local-name()}"><xsl:apply-templates select="@*|node()"/></xsl:element></xsl:template><xsl:template match="@*"><xsl:choose><xsl:when test="name() != ''xmlns''"><xsl:attribute name="{local-name()}"><xsl:value-of select="."/></xsl:attribute></xsl:when></xsl:choose></xsl:template></xsl:stylesheet>';

  • How to view file from vss using java Commandline

    Hi To ALL,
    I wanted to view a file from vss through java code.
    By using the folowing code,i could able to get vss file in to local folder.
    Runtime.getRuntime().exec
    ("cmd /c ss Get $/Mywork/Myfile.java -GLC:/New");
    But i wanted to view file from vss using java code.
    any one please help me..
    Thanks in advance.........

    As always, Google is your friend.
    Follow the bouncing link.
    http://www.google.com/search?hl=en&q=VisualSourceSafe+%2B+Java+API
    PS.

  • How to remove indents from XML?

    I have a xml like this:
    <?xml version="1.0" encoding="UTF-8"?>
    <view>
         <help>
              <block>No.1</block>
              <device>USB</device>
         </help>     
    </view>
    How could I output the xml to :
    <?xml version="1.0" encoding="UTF-8"?><view><help><block>No.1</block>          <device>USB</device></help></view>
    The reason to output like this is to make the xml comparison passed.
    I use org.custommonkey.xmlunit.XMLTestCase.compareXML to compare two xml string, one from Java code, the other from C# code. Now, since there are new lines and whitespaces embedded in the Java generated XML, the comparison always failed. Is there any way to output the indent xml to the one string only?

    Try running the strings through something like this before comparing:
    String <stringname> = <stringname>.replaceAll("\\n|\\t|\\s|\\r", "");
    that should normalize them both to no spaces, tabs, newlines, carrage returns.

  • How to remove objects from pics using LR...

    I am not a professional photographer and I do not have a whole lot of photo editing knowledge. I started out several years ago using Photoshop elements 5 and eventually learned how to do several things like moving objects around or removing them from a photo, or moving someone's face into a different picture if their eyes were closed and lots of nice editing features. I loved it and still love it. My laptop was getting really old and slow so I just recently purchased a new computer which has windows 8 on it. I loaded my photoshop elements and cannot get it to open or work properly and am wondering if it's because of the windows 8 operating system. So I then decided to purchase a new photo editing software. I decided (quickly.. too quickly) to purchase adobe lightroom just because it had very good reviews online. Now I have several pictures that need to be edited for Christmas and I cannot find any "lasso tool" or any thing similar right now.. I was so used to using the layers and features from the PE and now my heart is broken because I feel so lost and maybe broke at the same time!! This program is soooo different than what I was used to using but I don't even know if I can do the same things with it. EXAMPLE: there is an air conditioner unit in one of the photos I've taken and I was planning on removing it from the picture. Also I was aiming on moving a face over from another picture because of some closed eyes.. Someone please tell me, is this program capable of doing these things or can I only play with the lighting in this? Will I have to spend more of my $$ to get another Photoshop elements to get the features I use?

    These tasks are tasks for Photoshop or Photoshop Elements, not for Lightroom, which is more an image data base.

  • Remove tags from XML using transformation

    Can anybody tell me how to remove empty tags using xsl transformation.
    <App_Data App="MOD" Name="Metadata_Id" Value="SP1282"/>
    <App_Data App="MOD" Name="Metadata_Spec_Major_Version" Value=""/>
    <App_Data App="MOD" Name="Metadata_Spec_Minor_Version" Value=""/>
    My XML will have tags similar to above. My requirement is to remove all tags having attribute Value="". How can i achieve this using transformation.
    Thanks
    Krish

    You need to add the xsi:nil="true" attribute to your xsl-construct to be able to ommit the xml-element which are empty.
    To be able to do this you need to add a choose-when-otherwise xsl construct inside your mapping file to test for ""-values.
    The xsi:nill='true' isn't supported in the transform-activity yet, you need to add this attribute manually inside your xsl-mapping file.
    Kind regards,
    Nathalie

  • How to remove namespace from xml in ALSB?

    I have a xquery transformation which works for data without namespace. But the data coming from source system has namespace details in it. Is there a way to strip the xml of namespace details from xml before passing it to xquery transformation?

    Hi
    silly mistake :P
    Following 'bold' declaration was not there!!
    Just copy paste following code as xquery and it will be all ok:
    declare namespace xf = "http://tempuri.org/vijfhuizen/com/myMessage/";
    declare function xf:strip-namespace($e as element())
    as element()
    element { xs:QName(local-name($e)) }
    for $child in $e/(@*,node())
    return
    if ($child instance of element())
    then xf:strip-namespace($child)
    else $child
    declare variable $e as element() external;
    xf:strip-namespace($e)

  • How to retrieve information from XML using servlets

    Hi
    I have a scenario like this
    File-->XI-->J2ee application(HTTP Receiver adapter)
    I want to know how XI sends xml file as a query string file name?
    What ever may be the case i just need to retrieve the information from Request object and display the same in browser(JSP).How to do that, I am totally confused, please anyone help me!
    Code help is highly rewarded.
    Thanx

    Hi Rajesh!
    I have tried your code. But some where i went wrong. Please correct me: I am using NWDS2.0.9
    my web.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
                             "http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>
        <display-name>WEB APP</display-name>
        <description>WEB APP description</description>
        <servlet>
            <servlet-name>DisplayRes</servlet-name>
            <servlet-class>com.quinnox.DisplayRes</servlet-class>
        </servlet>
        <servlet-mapping>
              <servlet-name>DisplayRes</servlet-name>
              <url-pattern>/DisplayRes/*</url-pattern>
         </servlet-mapping>
    </web-app>
    my application.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE application PUBLIC "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN"
                                 "http://java.sun.com/dtd/application_1_3.dtd">
    <application>
        <display-name>ReceiverEntpr</display-name>
        <description>EAR description</description>
        <module>
            <web>
                <web-uri>HttpReceiver.war</web-uri>
                <context-root>/HttpReceiver</context-root>
            </web>
        </module>
    </application>
    and my servlet code:
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.PrintWriter;
    import java.io.Writer;
    import javax.servlet.ServletException;
    import javax.servlet.ServletOutputStream;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    import org.xml.sax.InputSource;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.transform.Result;
    import javax.xml.transform.Source;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.dom.DOMSource;
    import javax.xml.transform.stream.StreamResult;
    import org.xml.sax.EntityResolver;
    import org.xml.sax.SAXException;
    import com.sun.java_cup.internal.parser;
    import com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl;
    public class DisplayRes extends HttpServlet {
         public void doGet(HttpServletRequest requset, HttpServletResponse response) throws ServletException, IOException
              doWork(requset, response);
         public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
              doWork(req, resp);
         private void doWork(HttpServletRequest req, HttpServletResponse resp) throws IOException
              String path = null;
              PrintWriter out = null;
              PrintWriter p2=resp.getWriter();     
              try
                   resp.setContentType("text/xml");
                   out = resp.getWriter();
                   out.println("hi");
                   path = req.getPathInfo();
                   if(req.getContentLength() != -1){
                   outputURI(req.getInputStream(), out);
              } catch (IOException ioe) {     return;     
         //private void outputURI(InputStream resultStream, Writer out) {
              private void outputURI(InputStream resultStream, PrintWriter out) {
              if (resultStream == null) {
    //             no default file
    //            logger.error("No File to return");
              return;
              try {
              DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    //            Class clazz = loader.loadClass("org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
    //            DocumentBuilderFactoryImpl factory = (DocumentBuilderFactoryImpl) clazz.newInstance();
    //            DocumentBuilder parser = factory.newDocumentBuilder();
              parser.setEntityResolver(new ClassPathEntityResolver());
              printXML(parser.parse(resultStream), out);
              resultStream.close();
              } catch (Exception e) {
    //            logger.error("Trying to parse the output " , e);
         //private void printXML(Document document, Writer writer) throws Exception {
              private void printXML(Document document, PrintWriter writer) throws Exception {
              Transformer transformer = TransformerFactory.newInstance().newTransformer();
              Source source = new DOMSource(document);
              Result output = new StreamResult(System.out);
              transformer.transform(source, output);
    //             Write as XML so that entity references can be resolved.
              if (writer != null) {
              transformer.transform(source, new StreamResult(writer));
    Please tell me how to display in servlet.
    If it is better to display in a browser. Please send me the code.
    Thanks

  • How to create DTD from XML using DOM

    Hi,
    Is there a way to create a corrosponding DTD of a xml-file using DOM. I have a XML-file that's pretty huge I want to create a DTD for that XML-file using DOM. Can anyone plz. lead me how to do this. I tried to use XMLSpy to convert the XML into DTD but the resulting DTD is not correct. Is there a way to create the DTD using DOM.
    Any help is really appreciated. Thanks

    When you say you are trying to convert XML to DTD, do you mean you are trying to convert a XSD (schema) to a DTD, or that you are trying to create a schema that corresponds to a given XML document.
    Realize that DTDs are not very powerful. XSD documents allow for much more detail. I don't have a proof, but I'm absolutely confident that any DTD can be expressed as a schema but not all schemas can be represented as a DTD. In other words, DTDs are not worth the trouble, in my opinion.

  • How to remove subject from background using brush tool (Adobe Photoshop CS6)?

    A few months ago I successfully extracted a subject from a background. I used a method I found on a tutorial video. All that I can remember from the method was that the initial steps invovled coloring over my subject with a brush tool. Since then, however, I can no longer find the tutorial video. I am well aware of the existance of the magic wand and may in fact use this technique instead in the future. However, I'd like the opportunity to try out alternatives. Can anyone explain the brush method to me in detail or refer me to a tutorial/thread/etc that can? Other alternatives are also welcome. Many thanks.

    These tasks are tasks for Photoshop or Photoshop Elements, not for Lightroom, which is more an image data base.

  • How do remove the page number using java script.

    Thank you.

    Hello,
    Where you want remove the page number? If you delete the page number in the first page of the document, that is no way to do. Becasue, first you have to try manually remove the page number 1st page of pages panel, its shown the error "Invalid entry".
    Can you please post your query briefly.
    thx
    csm_phil

  • How to remove highlight from text using PDFReaderLight ?

    the question is as simple as that
    i can't seem to find a way
    pls help it's urgent
    have to e-mail it soon

    just set the width of the element to a static number, any
    additional text that goes past the width just won't display.

Maybe you are looking for

  • MacBook Pro error when trying to update Apps in Appstore

    I keep getting an Error that won't allow me to update the App--pop up tells me to use the Purchases Page to try again, which I've done, but I keep getting the same error. I updated my billing information, and have tried multiple procedures I've found

  • Sync abap outbound proxy steps

    Hi friends, Could you please help me to send the sync abap outbound proxy creation blogs. advanced thanks Rao

  • VHS Like New

    Started to transfer my old VHS into FCP and have balanced the whites and the blacks but i was wondering how i could reduce the grain from the tape, kinda would like to smooth out the picture some.

  • Cant install driver for Audigy

    Hm , i first installed the driver from the cd but then i wanted to have the latest driver so i uninstalled it and rebooted. yet when i run SBAX_WEBUP_LB_2_08_0004 which i downloaded from creatives website i get the error: You have previously installe

  • I cant sign in to icloud mail

    hi all, i am having major problems with mail starting yesterday. i have a .mac icloud address as i have mobile me for many years ( i also have an alias of a .me address on this acount) i have also created another icloud account with a new .me address