Dom importNode problem

hi, i have problems with this code:
public Document searchEngine(NodeList secNode){
     int i;
     Document newDoc=null;
     boolean trovato;
     try{
               DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
               DocumentBuilder builder = factory.newDocumentBuilder();
               newDoc = builder.newDocument();
               Element root = newDoc.createElement("document");
               newDoc.appendChild(root);
               for (i=0 ; i<secNode.getLength(); i++){
                    trovato=search(secNode.item(i));
                    if (trovato) newDoc.importNode(secNode.item(i),true);
               }                              f=false;
     }catch(Exception e){e.printStackTrace();}
     return newDoc;
I have another method that writ retuner dom document to file, but my secNode that i try to import with ImportNode aren't present...
btw i want an xml tree with:
<document>
imported node
imported node
</document>
what's wrong?
thanks, marco

ok i understand the problem..
importNode method work with apache xerces parser..

Similar Messages

  • DOM: parsing problem, inputstream

    Hi,
    We are developing a simple server that translates a XML query to a SQL query, sends that SQL query to the database, translates the result to a XML resultset and sends it back to the connecting client.
    We are using DOM to interpret the XML in order to build the XML query, since DOM builds a tree (that we use as a buffer), instead of SAX that has to be interpreted realtime.
    Our problem is as follows: the inputstream of the socket act as the input stream for DOM. No exception occures, but at the point when we call domParser.parse();, the thread hangs. When we close the connection, the local output (at the server) is done; the thread continues.
    We assume that the following causes the problem: the inputstream is used to read the XML from. But when the XML is sent over the stream, the stream is not closed. Somehow the parser still expects something. When the clientconnection is closed, the stream is closed and the thread can continue; the parser know that the input is ended.
    Do you know how to solve this? We cannot just close the connection, because we need to receive the result. Does the parser expects some end indicator? For the inputstream for the parser we use a BufferedReader (otherwise we are getting a NullPointerException).
    Thanks! And cheers,
    Jeroen Oosterlaar

    personaly, for doing a similar stuff, on the server I accumulate the XML lines received over the socket, until I bump into a pre-defined stop line, then I send the accumulated XML data to the parser.
    but it might not be the most elegant solution!

  • DOM Parsing problems... (newbie in trouble)

    I am trying to get a DOM Parser contruct a DOM Object from an XML file... I am having trouble getting the code validate against my XML Schema: <p>
    <?xml version="1.0" encoding="UTF-8"?> <
    <!-- edited with XML Spy v4.4 U (http://www.xmlspy.com) by Fedro E. Ponce de Leon Luengas (ASI Consulores, S.A. de C.V.) -->
    <xs:schema targetNamespace="http://palaciohierro.com.mx/mde/expe" xmlns="http://palaciohierro.com.mx/mde/expe" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="existencia-peticion" type="epType">
    <xs:annotation>
    <xs:documentation>Peticion de existencias para la Mesa de Eventos Web</xs:documentation>
    </xs:annotation>
    </xs:element>
    <xs:complexType name="epType">
    <xs:annotation>
    <xs:documentation>peticion de existencia</xs:documentation>
    </xs:annotation>
    <xs:sequence>
    <xs:element name="articulo" type="articuloType" maxOccurs="unbounded"/>
    </xs:sequence>
    </xs:complexType>
    <xs:complexType name="articuloType">
    <xs:annotation>
    <xs:documentation>articulo</xs:documentation>
    </xs:annotation>
    <xs:attribute name="id_articulo" type="IdentifierType" use="required"/>
    <xs:attribute name="sku" type="skuType" use="required"/>
    </xs:complexType>
    <xs:simpleType name="IdentifierType">
    <xs:annotation>
    <xs:documentation>identificador</xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:long">
    <xs:minInclusive value="0"/>
    <xs:maxInclusive value="999999999999999999"/>
    <xs:totalDigits value="22"/>
    <xs:fractionDigits value="0"/>
    </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="skuType">
    <xs:annotation>
    <xs:documentation>sku</xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:string">
    <xs:minLength value="11"/>
    <xs:maxLength value="20"/>
    <xs:pattern value="\d{11,20}"/>
    </xs:restriction>
    </xs:simpleType>
    </xs:schema>
    taking this sample XML file:
    <?xml version="1.0" encoding="UTF-8"?>
    <!--Sample XML file generated by XML Spy v4.4 U (http://www.xmlspy.com)-->
    <expe:existencia-peticion xmlns:expe="http://palaciohierro.com.mx/mde/expe" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://palaciohierro.com.mx/mde/expe
    C:\oracle\Oracle9iDS\jdev\mywork\testCompra\MesaEventos\src\ph\mesaeventos\schema\existencia-peticion.xsd">
    <articulo id_articulo="450" sku="12245110021"/>
    <articulo id_articulo="15" sku="45421213223"/>
    <articulo id_articulo="12" sku="121131231858"/>
    <articulo id_articulo="74" sku="4101031234545"/>
    <articulo id_articulo="871" sku="022324563212"/>
    </expe:existencia-peticion>
    with the following code:
    public Document getDOM( String existenciapeticionXML ) throws Exception
    // Obtain parser instance and parse the document
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating( true );
    factory.setNamespaceAware( true );
    DocumentBuilder builder = factory.newDocumentBuilder();
    byte buf[] = existenciapeticionXML.getBytes();
    ByteArrayInputStream stream = new ByteArrayInputStream( buf );
    Document doc = builder.parse( stream );
    return doc;
    I am getting the following Exception:
    oracle.xml.parser.v2.XMLParseException: Element 'expe:existencia-peticion' used but not declared.
    void oracle.xml.parser.v2.XMLError.flushErrors()
    XMLError.java:145
    void oracle.xml.parser.v2.NonValidatingParser.parseDocument()
    NonValidatingParser.java:263
    void oracle.xml.parser.v2.XMLParser.parse(org.xml.sax.InputSource)
    XMLParser.java:141
    org.w3c.dom.Document oracle.xml.jaxp.JXDocumentBuilder.parse(org.xml.sax.InputSource)
    JXDocumentBuilder.java:96
    org.w3c.dom.Document javax.xml.parsers.DocumentBuilder.parse(java.io.InputStream)
    DocumentBuilder.java:119
    org.w3c.dom.Document ph.mesaeventos.mesa.xml.ExistenciaPeticionDOM.getDOM(java.lang.String)
    ExistenciaPeticionDOM.java:26
    void ph.mesaeventos.mesa.xml.Test.main(java.lang.String[])
    Test.java:38
    What am I doing wrong? I am clueless... please help!
    Thanks,

    I finally managed to make it work.... well quite!
    Having an XML Doc like this:
    <?xml version="1.0"?>
    <existencia-peticion xmlns = "http://palaciohierro.com.mx/mde/expe">
    <articulo id_articulo="10" sku="00000000010"></articulo>
    <articulo id_articulo="11" sku="00000000011"></articulo>
    <articulo id_articulo="12" sku="00000000012"></articulo>
    <articulo id_articulo="13" sku="00000000013"></articulo>
    </existencia-peticion>
    with an schema like:
    <?xml version="1.0" encoding="UTF-8"?>
    <schema targetNamespace="http://palaciohierro.com.mx/mde/expe"
    xmlns="http://www.w3.org/2001/XMLSchema"
    xmlns:expe="http://palaciohierro.com.mx/mde/expe"
    elementFormDefault="qualified">
    <annotation>
    <documentation xml:lang="es">
    Esquema de peticion de existencias para la Mesa de Eventos Web
    Copyright 2002 palaciodehierro.com.mx. Todos los derechos reservados.
    </documentation>
    </annotation>
    <element name="existencia-peticion" type="expe:epType">
    <unique name="id_articulo">
    <selector xpath="expe:articulo"/>
    <field xpath="@id_articulo"/>
    </unique>
    <unique name="sku">
    <selector xpath="expe:articulo"/>
    <field xpath="@sku"/>
    </unique>
    </element>
    <complexType name="epType">
    <annotation>
    <documentation>peticion de existencias</documentation>
    </annotation>
    <sequence>
    <element name="articulo" type="expe:articuloType" maxOccurs="unbounded"/>
    </sequence>
    </complexType>
    <complexType name="articuloType">
    <annotation>
    <documentation>articulo</documentation>
    </annotation>
    <attribute name="id_articulo" type="expe:IdentifierType" use="required"/>
    <attribute name="sku" type="expe:skuType" use="required"/>
    </complexType>
    <simpleType name="IdentifierType">
    <annotation>
    <documentation>identificador</documentation>
    </annotation>
    <restriction base="long">
    <minInclusive value="0"/>
    <maxInclusive value="999999999999999999"/>
    <totalDigits value="18"/>
    <fractionDigits value="0"/>
    </restriction>
    </simpleType>
    <simpleType name="skuType">
    <annotation>
    <documentation>sku</documentation>
    </annotation>
    <restriction base="string">
    <minLength value="11"/>
    <maxLength value="20"/>
    <pattern value="\d{11,20}"/>
    </restriction>
    </simpleType>
    </schema>
    and with the following class:
    public class XMLValidator
    // Instancia singleton
    private static XMLValidator validator = new XMLValidator();
    * Constructor privado
    private XMLValidator()
    * Mitodo para acceder a la instancia Singleton de XMLValidator
    * @regresa <b>XMLValidator</b> La instancia de esta clase
    public static XMLValidator getValidator()
    return validator;
    public boolean validaEsquema( String docXML, String esquema ) throws Exception
    // Establece el URL correcto para el documento de esquema
    XSDBuilder builder = new XSDBuilder();
    URL url = createURL( esquema );
    // Construye el objecto del Schema XML
    try
    XMLSchema schemadoc = (XMLSchema)builder.build( url );
    // Valida el documento XML procesandolo contra el esquema
    return validate( docXML, schemadoc );
    catch( XMLParseException e )
    throw new Exception( "Error al analizar el documento XML: " + e.getMessage() );
    catch( Exception e )
    throw new Exception( "No es posible validar con el esquema: " + e.getMessage() );
    private static boolean validate(String docXML, XMLSchema schemadoc) throws Exception
    boolean isValid = false;
    // Crea un objeto Parser DOM de XML
    DOMParser dp = new DOMParser();
    // Establece el objeto Schema XML para la validacion
    dp.setXMLSchema( schemadoc );
    dp.setValidationMode( XMLParser.SCHEMA_VALIDATION );
    dp.setPreserveWhitespace( true );
    // Establece la salida de errores
    dp.setErrorStream( System.out );
    // Recupera los datos del documento XML en un objeto InputStream
    byte[] docbytes = docXML.getBytes();
    ByteArrayInputStream in = new ByteArrayInputStream( docbytes );
    // Parsea el documento y validalo contra el esquema
    try
    dp.parse( in );
    isValid = true;
    catch( Exception e )
    // Devuelve el documento XML DOM construido durante el parseo
    return isValid;
    I am able to validate when invoking with the XML and schemas in the parameters...
    Problem is that I have to include the attribute xmlns = "http://palaciohierro.com.mx/mde/expe" in my XML doc.
    What I really need is to be able to validate de XML doc against a stablished schema, when the XML doc does not include the
    xmlns attribute.

  • XDK 10.1.0.2.0 NT XMLType and org.w3c.dom.Document problem/bug?

    Hi Chaps,
    I have Oracle 11g1 server side and am using the Oracle XDK 10.1.0.2.0 for Windows client side with Sun Java JDK 6 (1.6.0_06-b02).
    (I couldnt find an XDK for 11g1???)
    I have a table in my database that has an XMLType, its a very simple table -
    CREATE TABLE hcr_xml_test
    RRN VARCHAR(24) PRIMARY KEY,
    ClipID VARCHAR2(27),
    Lodgement XMLType
    XMLTYPE COLUMN Lodgement
    STORE AS OBJECT RELATIONAL
    ELEMENT "/www.hcrregister.com/RequestServices/Messages/ConditionReportCreateRequest_1.xsd#ConditionReportCreateRequest_1"
    Thats all fine, however with the XDK I am trying to construct an XMLType for use with JDBC from a valid org.w3c.dom.Document so that I can insert a row into my table. My code looks like this -
    XMLType xml = new XMLType(realCon, doc);
    stmt = (OraclePreparedStatement) realCon.prepareStatement(sql);
    stmt.setString(1, id.getRRN());
    stmt.setString(2, id.getCenteraClipID());
    stmt.setObject(3, xml);
    stmt.execute();
    doc is a org.w3c.dom.Document
    realCon is a java.sql.Connection
    That code throws a SQLException at the line "stmt.setObject(3, xml);" -
    java.sql.SQLException: Fail to convert to internal representation
    at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
    at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:112)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:173)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:229)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:403)
    at oracle.sql.OPAQUE.<init>(OPAQUE.java:85)
    at oracle.xdb.XMLType.toDatum(XMLType.java:480)
    at oracle.jdbc.driver.OraclePreparedStatement.setORADataInternal(OraclePreparedStatement.java:7437)
    at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:8158)
    at oracle.jdbc.driver.OraclePreparedStatement.setObject(OraclePreparedStatement.java:8149)
    at oracle.jdbc.driver.OraclePreparedStatementWrapper.setObject(OraclePreparedStatementWrapper.java:229)
    at uk.co.landmarkinfo.registers.datawarehouse.tools.oracle.lodgementloader.DocumentProcessor.run(DocumentProcessor.java:232)
    Inspecting the exception I can see that the vendorCode is 17059.
    If I use "XMLType xml = XMLType.createXML(realCon, doc);" then xml is null instead of throwing a SQLException, so something isnt working here...
    However, if I serialize my Document to a String first and give that String to either the XMLType Constructor or XMLType.createXML() then it all works fine -
    /////TEMP
    Transformer transformer = saxTransformerFactory.newTransformer();
    transformer.setOutputProperty("omit-xml-declaration", "no");
    transformer.setOutputProperty("indent", "yes");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    transformer.transform(new DOMSource(doc), new StreamResult(baos));
    XMLType stringXML = new XMLType(realCon, new String(baos.toByteArray()));
    ////END TEMP
    stmt = (OraclePreparedStatement) realCon.prepareStatement(sql);
    stmt.setString(1, id.getRRN());
    stmt.setString(2, id.getCenteraClipID());
    stmt.setObject(3, stringXML);
    stmt.execute();
    But why do I need to serialize to a String first??? Looking at the javadoc I dont think I should have to do this. So is there a problem in Oracles XDB handling of Document or have I missed something?

    Anyone has any idea? Please help!!!
    xu

  • AirPort Extreme (Dome Style) problem after hard reset

    Our AE quit responding so I did a hard reset and now the AE asks for password when trying to set up. Enter "public" as stated in instructions and receive "unknown error (-6753)" Now I can't change any settings on it and can't use it until I change settings. I have reset this unit many times and have never had a problem. I hope it hasn't cratered...the new ones don't work on dial-up...this one was perfect!!! Any help would be greatly appreciated. Thanks in advance.

    try this:
    .Take a note of the IP address that is displayed for the AEBS.
    .On your PC, go to Control Panel and open Network Connections.
    .Select the Wireless Network Connection and select the Internet Protocols (TCP/IP) properties.
    .Select "Use the following address" and enter an address in the same subnet as your AEBS (offset the AEBS address by 1 - if your router is 10.0.1.1 enter 10.1.1.2 as your laptop's address).
    .Use the default subnet mask
    .Enter the router's IP address as your "Default Gateway"
    Close your your network settings windows and you should now be able to download the config of your router. Update your config to what you want it to be and reload the router.
    Once it comes back to life, go through the above again and set your laptop to accept addresses via DHCP (select "Obtain IP address automatically").
    You should be good to go now and be able to manage the AEBS normally.
    Good luck!

  • DOM document problem

    Hello,
    We created webservice based on example EchoDom. When we post
    XML document (where elements have attributes) to webservice, then the following
    excetption occurs:
    weblogic.xml.stream.XMLStreamException: ':' expected a valid beginning name character
    - with nested exception:
    [Error at line:2 col:8  ':' expected a valid beginning name character]
    javax.xml.soap.SOAPException: failed to receive message:
    at weblogic.webservice.core.DefaultWebService.invoke(DefaultWebService.java:218)
    at weblogic.webservice.server.servlet.ServletBase.serverSideInvoke(ServletBase.java:362)
    at weblogic.webservice.server.servlet.WebServiceServlet.serverSideInvoke(WebServiceServlet.java:269)
    at weblogic.webservice.server.servlet.ServletBase.doPost(ServletBase.java:346)
    at weblogic.webservice.server.servlet.WebServiceServlet.doPost(WebServiceServlet.java:237)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1058)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:401)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:306)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:5412)
    at weblogic.security.service.SecurityServiceManager.runAs(SecurityServiceManager.java:744)
    at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3086)
    at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2544)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:153)
    XML is quite simple for illustrative purposes:
    <test>
    <data Id="D1"/>
    </test>
    If we remove attributes
    <test>
    <data>some data</data>
    </test>
    then everything works fine.
    Does anybody know the solution to that problem?
    Ago

    On Mon, 10 Feb 2003 08:34:23 -0800, Ago Meister wrote:
    >
    Hello,
    We created webservice based on example EchoDom. When we post
    XML document (where elements have attributes) to webservice, then the following
    excetption occurs:Can you please run with the system property weblogic.webservice.verbose
    set to true and post the request and response xml?

  • DOM removeChild problem

    I am trying to delete all nodes from one parent node using the code below. However, this is not working. I have 12 children, but it only loops 6 times and also, the original xml file is not changed. The question that I have is, do I need to save the DOM doc back in order for the changes to take affect and also, why doesn't this code loop 12 times.
    NodeList nd3 = nd2.item(0).getChildNodes();
    System.out.println(nd3.getLength()); <-- prints 12
    for (int m = 0; m < nd3.getLength(); m++) {
      Node nod2 = nd3.item(m);
      Node parent = nod2.getParentNode();
      parent.removeChild(nod2);
    System.out.println(nd3.getLength()); <-- prints 6Thanks. Luke

    The classic delete-all gotcha!
    You have children A, B, C, D, E, F (let's limit the example to 6).
    You remove index 0, now you have children B, C, D, E, F.
    You remove index 1, now you have children B, D, E, F.
    You remove index 2, now you have children B, D, F.
    You remove index 3... there isn't any index 3 so nothing happens. And so on.
    How to fix your code? Always remove index 0 is one way.
    PC&#178;

  • Printing problem on Windows 7 - 64 bits

    I have problems printing some PDFs to Windows 7 - 64 bits. (Reader X 10.1.1)
    I'm attaching a picture of what I see on the screen, and the garbled characters that come out of the printer.
    On screen:
    Printed:
    This looks like a font problem. So I checked the properties and all the fonts have "Embedded subset".
    Also note that:
    1. The same document prints perfectly on an XP machine that has the same fonts;
    1.b. The same document prints perfectly on a Windows 7 - 32 bit machine;
    2. The same document prints perfectly using Foxit Reader;
    3. The same characters are printed on both paper output and XPS output.
    I've been banging at that issue since over a month, deforesting a large part of the tundra in the process (that is, until I confirmed that XPS printer had the same problem...)
    - I've reinstalled the fonts several times;
    - I've rebooted the machine often;
    - Everything is at the latest version.
    Any help would be welcome.
    Regards,
    Dom

    I have problems printing some PDFs to Windows 7 - 64 bits. (Reader X 10.1.1)
    I'm attaching a picture of what I see on the screen, and the garbled characters that come out of the printer.
    On screen:
    Printed:
    This looks like a font problem. So I checked the properties and all the fonts have "Embedded subset".
    Also note that:
    1. The same document prints perfectly on an XP machine that has the same fonts;
    1.b. The same document prints perfectly on a Windows 7 - 32 bit machine;
    2. The same document prints perfectly using Foxit Reader;
    3. The same characters are printed on both paper output and XPS output.
    I've been banging at that issue since over a month, deforesting a large part of the tundra in the process (that is, until I confirmed that XPS printer had the same problem...)
    - I've reinstalled the fonts several times;
    - I've rebooted the machine often;
    - Everything is at the latest version.
    Any help would be welcome.
    Regards,
    Dom

  • I put dom storage on "false" and now I can't do a Google search. A few days ago I could search Google with dom on false. What changed?

    I customized the Firefox using 'about:config' and all the other settings work well with Google search - for example geo_enabled which I set to false.
    The one setting that has suddenly proved problematic is dom_storage. I used it in false mode successfully for months when searching on Google, now the setting has resulted in an inability to search on Google. The Google page with search bar comes up as usual when I open the browser, but with dom storage set to "false" I can't search anything - the Google search bar page just remains static.

    Users who disable DOM storage in IE8 and IE9 are reporting the same problem on Google's web search forum. For that reason, the requirement to allow DOM storage sounds like a change in Google's code rather than a browser-specific issue.
    One Firefox-specific issue is the cookie connection: Firefox appears to use cookie permissions to block DOM storage on a site-by-site basis. So if you block cookies for google.com, the DOM storage problem will kick in.

  • HELP!!! add new node

    Friends,
    Suppose I have following xml
    <?xml version="1.0" encoding="UTF-8"?>
    <Organisation name="abc">
    <employee>
    <name>e1</name>
    <age>20</age>
    </employee>
    <employee>
    <name>e2</name>
    <age>20</age>
    </employee>
    <employee>
    <name>e3</name>
    <age>21</age>
    </employee>
    </Organisation>
    Suppose I have to add one more record to it at a particular location (not necessarily at the end)
    <employee>
    <name>e4</name>
    <age>22</age>
    </employee>
    What is the preferred way to do it ?
    XML file is very large in actual scenario.
    Earlier I faced problems in reading my XML file using DOM (outOfMemory problem) so I used SAX. Now also I want to use SAX for this(JAXP). But I am unable to find any sample code for it.
    Some people suggest to use JDOM in stead.
    Pls suggest ASAP.
    waiting
    regards
    Varun

    Refer to
    http://javaalmanac.com/egs/org.w3c.dom/AddNode.html

  • Encore WT8 - How to get office in english for Windows 8.1

    Hi,
    I have just bought an Encore/Windows 8.1 in Belgium; on the web site, it was indicated that this tablet is in french/dutch/english; but during the installation I had only french and dutch; no problem, I have switched all in english after installation but now, when I want to install Office, the only choice I have is french and dutch (for nederlands) !!!
    How can I get an english version of Office ?
    thanks in advance,
    Domi.

    No problem. I have a german tablet, but office in English. I did this last December, but if I remember right, I visited http://office.microsoft.com/en-in/products/download-back-up-restore-microsoft-office-products-FX103427465.aspx and downloaded a copy.
    It asks you for your license key from the piece of paper that came with the tablet.

  • Problem in reading with DOM

    i have the following xml file to read with DOM
    <?xml version="1.0" encoding="UTF-8" ?>
    - <usecasediag>
    - <actor id="1">
      <name>customer</name>
      <usecase>reservation of tour</usecase>
      <usecase>view tour data</usecase>
      <usecase>cancel reservation</usecase>
      <usecase>complain</usecase>
      </actor>
    - <actor id="2">
      <name>employee</name>
      <usecase>access</usecase>
      <usecase>update</usecase>
      </actor>
    </usecasediag>after reading the above file i need to create another XML file using DOM. I have the following code but i am not able to get the value "customer","enployee" while reading the XML file....
    import java.io.File;
    import java.io.IOException;
    import org.w3c.dom.*;
    import javax.xml.parsers.ParserConfigurationException;
    import com.sun.org.apache.xml.internal.serialize.OutputFormat;
    import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
    class Post
       Document dom; //to read
       Document dwrite; //to write
       Element root;//to read
       Element rootEle;//to write
       Post()
            File docFile = new File("..\\uml\\xml file\\sample.xml");
            try {
                DocumentBuilderFactory dbf =DocumentBuilderFactory.newInstance();
                DocumentBuilder db = dbf.newDocumentBuilder();
                dom= db.parse(docFile);
                  } catch (java.io.IOException e)
                System.out.println("Can't find the file");
                } catch (Exception e)
                System.out.print("Problem parsing the file.");
            Element root = dom.getDocumentElement();
            findActor();
    void findActor()
         Element ele=null;     
         NodeList nl1 = dom.getElementsByTagName("actor");
         if(nl1 != null && nl1.getLength() > 0)
             for(int i = 0 ; i < nl1.getLength();i++)
                   //get each actor element
                   ele = (Element)nl1.item(i);
                   Node nameEle=ele.getFirstChild();//name element
                   Node actnm=nameEle.getFirstChild();//customer
                   String clname=actnm.getNodeValue();
             }//for
         }//if               
    }//classcan anyone figure out the problem...thanx in advance

    you are right...its taking empty tag...i tried doing it some other way but the control is not matching the "if" statement....can you please tell me how do i write code to get the name & usecase element for each actor..
    void findActor()
         Element ele=null;     
         NodeList nl1 = dom.getElementsByTagName("actor"); //all actor tags in XML
         if(nl1 != null && nl1.getLength() > 0)
             for(int i = 0 ; i < nl1.getLength();i++)
                   //get each actor element
                   ele = (Element)nl1.item(i);
                   for(Node child=ele.getFirstChild();child!=null;child=child.getNextSibling())
              if(child.equals("name"))
              { System.out.println("got it");
                   break;
             }//for i loop
         }//if               
    }

  • Problem in the Parsing (XML to DOM)

    Hi all , In our scenario we are trying to create a DOM tree from a XML file  but we are getting the error in the following statement 
    l_rc = if_iparser->parse( ).
    when we track the error using
      i = l_error->get_line( ).           (result 0)
      i = l_error->get_column( ).     (result 2017)
      str = l_error->get_reason( ).   (Expected '<' or '/>' tag)
    but strange thing is we can open the file using Stylus studio/ Altova / IE ..so may the problem is not in the XML file ....Has anybody faced the problem before ??
    Kind regarrds
    Goutam

    Data error

  • Problem in parsing XML using DOM Parser.

    Hi,
    I am parsing an XML using DOM Parser.
    When i try to get attributes of a node, i dont get in the order it is written. For Eg. This the node:
    <Level0 label="News" link="/website/ing_news.nsf/ViewNewsForm?OpenForm&All" level="202" uid="COGN-4MNMT3" parentid="aaaa">
    When i try to print the attribute values i should get in the order:
    News, /website/ing_news.nsf/ViewNewsForm?OpenForm&All, 202, COGN-4MNMT3, aaaa
    BUT I AM GETTING IN THE ORDER:
    News, 202, /website/ing_news.nsf/ViewNewsForm?OpenForm&All, aaaa, COGN-4MNMT3
    Is there any way to sort this problem out?
    Thanks and Regards,
    Ashok

    Hi Guys,
    Thanks a lot for your replies.
    But i want to keep all the values as attributes only.
    the XML file is as shown below:
    <Menu>
    <Level0 label="News" link="/website/ing_news.nsf/ViewNewsForm?OpenForm&All" level="202" uid="COGN-4MNMT3" parentid="aaaa" children="3">
         <Level1 label="ING News" link="" level="1" uid="COGN-4MNN89" parentid="COGN-4MNMT3" children="3" >
              <Level2 label="All ING News" link="/website/ing_news.nsf/ViewNewsForm?OpenForm&All" level="2" uid="INGD-4MVTK2" parentid="COGN-4MNN89" children="0">
              </Level2>
    </Level1>
    </Level0>
    The code i was using to get attributes is:
    String strElementName = new String(node.getNodeName());
         // System.out.println("strElementName:"+node.getNodeName());
    NamedNodeMap attrs = node.getAttributes();
    if (attrs != null) {
    int iLength = attrs.getLength();
    for (int i = 0; i < iLength; i++) {
    String strAttributes = (String) attrs.item(i).getNodeName();
    String strValues = (String) attrs.item(i).getNodeValue();
    Also is it not possible to Enforce the order using some Schema/DTD in this case?
    TIA
    Ashok

  • Dom Parsing and BR tag problem...

    hi all,
    I have a Dom parser which examines an xml file and creates a Jtree from its content... it works fine except that when it meets a </br> tag it creates a new node for it in the tree... is there anyway to get it to consider the two "node" as one...
    example:
    - <p>
    some text 1
    some text 2
    </p>
    should be added in one node as some text 1 some text 2 instead it puts some text 1 in one node and some text 2 in another....
    thanks
    Lila

    oooh sorry i didnt check how the message looked this is the question:
    hi all, I have a Dom parser which examines an xml file and creates a Jtree from its content... it works fine except that when it meets a / BR tag it creates a new node for it in the tree... is there anyway to get it to consider the two "node" as one... example: -
    < p >
    some text 1
    < / BR > <--- THIS NODE IS PROBLEM
    some text 2
    < / p >
    should be added in one node as some text 1 some text 2 instead it puts some text 1 in one node and some text 2 in another....
    thanks
    Lila

Maybe you are looking for