Is DocumentBuilder.parse(..) reading the whole XML into memory?

Hello,
I have a quick question about the following code snippet:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse("books.xml");Please have a look at the last line "builder.parse("books.xml");". I would like to use XPath to retrieve some informations of a xml file without having to deserialize the whole file (since the XML file rather big and I need to go through several of them in a loop).
What exactly does the "builder.parse(...)" method? Is it reading the XML file and writing all the content to memory? Or does it only analyze and read the structure of the XML code? Or in other words, is the text of an element "//books/title" in memory after parsing, or not until I really access the "title" node of that XML?
Thanks a lot for your help
Best Regards,
Ben

Hi ,
I did'nt knew how to start a new thread , so i am asking the question here:
===========================================================
I am trying to read a xml file but i am not able to do so properly. I am new to xml .
am trying to read a xml file of the following format in the staf and stax job xml file:
<?xml version="1.0" encoding="utf-8"?>
<operating_system>
<unix_80sp1>
<tests type="quick_sanity_test">
<prerequisitescript>preparequicksanityscript</prerequisitescript>
<acbuildpath>acbuildpath</acbuildpath>
<testsuitscript>test quick sanity script</testsuitscript>
<testdir>quick sanity dir</testdir>
</tests>
<machine_name>u80sp1_L004</machine_name>
<machine_name>u80sp1_L005</machine_name>
<machine_name>xyz.pxy.dxe.cde</machine_name>
<vmware id="155.35.3.55">144.35.3.90</vmware>
<vmware id="155.35.3.56">144.35.3.91</vmware>
</unix_80sp1>
</operating_system>
Here machine_name tag can be n number. I need to read all the machine_name tags in an array , so that i can use them later.
Also i need to read all the vmware tags in an array (both value and attributes) so that i can use them later. The number of vmware tags can again be n numbers.
I am trying to use the following code :
<!-- ******************************************************************* -->
<!-- Following function is used to parse an XML file and return the DOM -->
<!-- document object -->
<!-- ******************************************************************* -->
<function name="parseXML" scope="local">
<function-list-args>
<function-required-arg name="xmlFileName">
Name of file containing XML to be parsed
</function-required-arg>
</function-list-args>
<sequence>
<!-- Parse the XML -->
<script>
factory = DocumentBuilderFactory.newInstance();
factory.setValidating(1)
factory.setIgnoringElementContentWhitespace(0)
builder = factory.newDocumentBuilder()
document = builder.parse(xmlFileName)
</script>
<script>
vmware = None
machine_name = None
# Get the text value for the element with tag name "vmware"
nodeList = document.getElementsByTagName("vmware")
for i in range(nodeList.getLength()):
node = nodeList.item(i)
if node.getNodeType() == Node.ELEMENT_NODE:
children = node.getChildNodes()
for j in range(children.getLength()):
thisChild = children.item(j)
if (thisChild.getNodeType() == Node.TEXT_NODE):
machine_name = thisChild.getNodeValue()
# Get the text value for the element with tag name "machine_name"
nodeList = document.getElementsByTagName("vmware")
for i in range(nodeList.getLength()):
node = nodeList.item(i)
if node.getNodeType() == Node.ELEMENT_NODE:
children = node.getChildNodes()
for j in range(children.getLength()):
thisChild = children.item(j)
if (thisChild.getNodeType() == Node.TEXT_NODE):
machine_name = thisChild.getNodeValue()
</script>
<return>[machine_name,vmware]</return>
</sequence>
</function>
I am able to read only one value for machine_name (u80sp1_L005) and also one value for vmware
i.e 144.35.3.91.
What i want is read all the machine_value tags into a list , so that i can use it later
Also i want to read all the vmware tags attributes into a list and all corresponding values into another list.
what i mean is considering the following:_
<machine_name>u80sp1_L004</machine_name>
<machine_name>u80sp1_L005</machine_name>
<machine_name>xyz.pxy.dxe.cde</machine_name>
<vmware id="155.35.3.55">144.35.3.90</vmware>
<vmware id="155.35.3.56">144.35.3.91</vmware>
read all machine_name tag values into one list (u80sp1_L004,u80sp1_L005,xyz.pxy.dxe.cde)
also all vmware attributes into one list *(155.35.3.55,155.35.3.56).....*and all the vmware values into one list *(144.35.3.90,144.35.3.91)*
Also a good link to understand parsing using doumentbilder factory would be good help.
Regards
Sangram
mail: [email protected]

Similar Messages

  • Question to load the entire database into memory.

    I am planing to load the whole database into memory. Suppose mydb is 10G. Then I plan Max Memory for 10G. Then I can create a named cache with 10G and bind the mydb to this cache. Is this the best way to load entire db into memory?
    If the whole db can be loaded into memory, if procedure cache, cache for tempdb and all other params are not important any more? Or still need to follow common practice to configure memory params?

    Hi Kent,
    12-15GB sounds reasonable.
    I recommend always including your version with your initial posting (unless the version simply doesn't apply to the question).  Particularly when running an unusual version, and 12.5.x has been end-of-lifed long enough to be unusual now.  Are you running SAP Applications on this system?  If not, please questions post to the SAP Adaptive Server Enterprise (SAP ASE) for Custom Applications space instead, it is the space for general-purpose ASE questions.
    Cheers,
    -bret

  • JSP compiler reading the web.xml file?

    Hi,
              I am trying to use the weblogic JSP compiler (weblogic.jspc) to
              pre-compile some JSP that use custom tags. Does the compiler
              read the web.xml file if there is one? In particular the taglib
              elements in that file so that the compiler understands the
              <%@ taglib ... %> directive.
              In the JSP I try to compile I use this statement to declare a taglib:
              <%@ taglib uri="xyz/xyz-taglib" prefix="xyz" %>
              and in my web.xml I have:
              <taglib>
              <taglib-uri>xyz/xyz-taglib</taglib-uri>
              <taglib-location>/WEB-INF/tlds/xyz.tld</taglib-location>
              </taglib>
              When I try to compile the JSP I get the following error:
              Could not parse embedded JSP code: weblogic.utils.ParsingException: nested
              IOException: java.io.IOException: cannot resolve 'xyz/xyz-taglib' into a
              valid tag library.
              Any ideas how I can resolve this?
              In advance thank you for any help.
              Florian
              

    open it in a text editor and modify it.
    %

  • How to get the WHOLE xml document inside a string using XSLT mapping

    Hi folks,
    I have a deep xml structure that I want to embed as body, tags included, in a mail message (not as an attachment).
    I'm trying to use Michal's method in this blog
    /people/michal.krawczyk2/blog/2005/11/01/xi-xml-node-into-a-string-with-graphical-mapping
    However, I can't get it to deliver the entire structure instead of just specific elements.
    Any help is greatly appreciated,
    Thanks,
    Guy

    Ashok,
    I was able to work it out for my case.
    This XSL......
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
    <inside>
    <namestring>
    <xsl:text disable-output-escaping="yes"><![CDATA[<![CDATA[]]></xsl:text>
    <xsl:copy-of select="outside/name/*"/>
    <xsl:text disable-output-escaping="yes"><![CDATA[]]]]></xsl:text>
    <xsl:text disable-output-escaping="yes"><![CDATA[>]]></xsl:text>
    </namestring>
    </inside>
    </xsl:template>
    </xsl:stylesheet>
    ...will transform this input....
    <?xml version="1.0" encoding="UTF-8"?>
    <outside>
    <name>
    <nameone>name1</nameone>
    <nametwo>name2</nametwo>
    <namethree>name3</namethree>
    </name>
    </outside>
    ...and put the whole lot into the CDATA element.
    Hope this helps you,
    Guy

  • How do I activate mozzilla acct,I am asked to activate account, click the link or copy and paste the whole thing into your browser's location bar

    welcome to support.mozilla.com
    before you can use your new account you must activate it-this ensures the e-mail address you used is valid and belongs to you.To account,click the link below or copy and paste the whole thing into your browser's bar:
    https://support.mozilla.com/en-US/users/actiate/656ec47229 etc.
    tell me how to do this, if possible.

    '''waiting for reply, will there be a reply?'''

  • How to read the whole name of a music title while scrolling down a list of titles? With the new iOs7 Music App there is no more black box showing the entire name!

    How to read the whole name of a music title while scrolling down a list of titles? The old software-app had the function to click for a longer time on a titles beginning letters until a black box revealed the entire name. I miss this function especially for my classical music, because lots of pieces start with similar words. E.g.:
    "Beethoven: Variations On "Ein Mädchen Oder Weibchen", Op. 66 - Var. 1"
    "Beethoven: Variations On "Ein Mädchen Oder Weibchen", Op. 66 - Var. 2"
    Scrolling in a list of title, I can't distinguish the titles, because just the first words are shown followed by: "...".
    That's horrible!

    Or you could include a width to your body style:
    body {
    background-image: url(Logo/sky1.jpg);
    background-position: center center;
    background-attachment: fixed;
    width: 75%;}
    It might work or not depending on your other color scheme.

  • How to read the whole text file lines using FTP adapter

    Hi all,
    How to read the whole text file lines when error occured middle of the text file reading.
    after it is not reading the remaining lines . how to read the whole text file using FTP adapter
    pls can you help me

    Yes there is you need to use the uniqueMessageSeparator property. Have a look at the following link for its implementation.
    http://download-west.oracle.com/docs/cd/B31017_01/integrate.1013/b28994/adptr_file.htm#CIACDAAC
    cheers
    James

  • File adapter didn't read the whole file

    Hi folks,
    we use the file adapter since 1 year and in the majority of cases it works fine. But sometimes the file adapter didn't read the whole file. In SAP we are missing some parts. Funnily enough in this cases he archive the whole file and not only the executed parts . Know anybody whats the reason of this effect and how we can solve it?
    Kind regards Johann M.

    Johann
    I think you miss understood me/I didn;t explain myself very well....
    If you take the file that doesn't work/process correctly, can you replicate the issue where the whole file is not copied across.
    If you can, you should be able to extend the FTP/File adapter trace file to find the cause if this issue.
    Log onto Visual Admin.
    &#61680;     Services
    &#61680;     Log Configurator
    &#61680;     Locations
    &#61680;     Choose the location (Java package) and the tracing level (severity)
    (for example, com.sap.aii.adapter.file)
    &#61680;     Root Location > com > sap > aii > File
    &#61680;     Set the severity and choose Copy Severity to Subtree
    Run interface and then check the trace file - remember to switch this back to Error...

  • I have adobe illustrator CS5. When I save a document as a pdf and open it again later to edit Adobe reader can't read the whole document because it only shows part of the document. It is very frustrating. How can I fix this?

    I have adobe illustrator CS5. When I save a document as a pdf and open it again later to edit Adobe reader can't read the whole document because it only shows part of the document. It is very frustrating. How can I fix this?

    keokipineapples schrieb:
    I do have all of my files I am working on located on an external drive. I plan to transfer them directly to the hard drive
    Transfer them to your harddisk immediately.
    External drives are not offiially supported and the source of errors of all kinds including complete loss of files.
    Illustrator support for networks and removable media

  • How can I read the trace data into LabVIEW for E5071B

    HI 
    I am setting up the measurement using vector network analyzer (VNA) E5071B controlled by NI 488.2. How can I read the trace data into LabVIEW and display on the graph? If anyone having an idea or know well about this process please give me the suggestion, I will much appreciate it.
    Many Thanks

    You want to start with the driver
     In case you do not know it, you can do the driver search in LabVIEW from Tools>Instrumentation>Find Instrument Drivers. You might also want to bookmark the Instrument Driver Network for information on what a driver is and how to use it.

  • How do I turn selected text in a Pages document into two columns without turning the whole document into two columns?

    How do I turn selected text in a Pages document into two columns without turning the whole document into two columns?

    Menu > Insert > Layout Break (before and after text) > click in text > Inspector > Layout > Layout > columns: 2
    Peter

  • HT3680 where can i find this program after reading the whole story?

    where can i find this program after reading the whole story?

    could this knowledge base article be what your looking for?:
    HT3680

  • Updating the whole xml file in  XMLType column

    Hi ,
    I am facing the problem in updating the XMLTYPE column.
    I need to update the whole xml file
    This is my table
    SQL> desc EMPJAL_TABLE;
    Name Null? Type
    EMPLOYEEID NOT NULL VARCHAR2(140)
    EMPCOM VARCHAR2(100)
    EMPJAL SYS.XMLTYPE(XMLSchema "www.EMPSIM.com" Element "EMPJAL") STORAGE
    Object-relational TYPE "EMPJAL_T"
    I am able to form the CLOB object and trying to use this sql command
    UPDATE EMPJAL_TABLE SET EMPJAL = XMLType( ? ) ) WHERE EMPLOYEEID ='emp1234';
    Here I want to update the whole xmlfile in XMLTYPE column.
    Error is - ORA-00933: SQL command not properly ended
    Please advise
    Thanks
    Govinds

    Hi Mark,
    I apologise for this mistake. I am really putting lot of efforts and also worked/working in advance topics of XML DB.
    Yes I am extensively using Oracle 10g r2 and suggesting others to use this
    This time I had put more effort before posting ,I had a series of queries to resolve most of then were working , this was the one giving problem inside my java code
    I am sorry for this .
    Any how I made another query which works better.
    Thanks
    Govinda

  • How to read the CSV Files into Database Table

    Hi
    Friends i have a Table called tblstudent this has the following fields Student ID, StudentName ,Class,Father_Name, Mother_Name.
    Now i have a CSV File with 1500 records with all These Fields. Now in my Program there is a need for me to read all these Records into this Table tblstudent.
    Note: I have got already 2000 records in the Table tblstudent now i would like to read all these CSV File records into the Table tblstudent.
    Please give me some examples to do this
    Thank your for your service
    Cheers
    Jofin

    1) Read the CSV file line by line using BufferedReader.
    2) Convert each line (record) to a List and add it to a parent List. If you know the columns before, you might use a List of DTO's.
    3) Finally save the two-dimensional List or the List of DTO's into the datatable using plain JDBC or any kind of ORM (Hibernate and so on).
    This article contains some useful code snippets to parse a CSV: http://balusc.xs4all.nl/srv/dev-jep-csv.html

  • JCA - Reading the RFC export  into array

    Iam successful in connecting to an RFC using JCA.
    Iam trying to display the table values like:
    table.beforeFirst();
    while(table.next()){
    String s1 = table.getString("column_1");
    There are lot of values under column_1.If i try to display the column_1 like:
    response.write(s1);
    Itz only outputting the last column's value.
    Guess it should be handled using arrays or vector in Java.
    I need to get all the values of Column_1 from a dropdown Box.
    Can i actually read the values into a dropdownbox on JSP directly?
    Cud someone Help me out!!
    Thanx
    Naresh.

    I still haven't gotten your email with code. This is what you need to do.
    1. Modify your bean.
    Add this import in your bean
    import com.sap.htmlb.IListModel;
    import com.sap.htmlb.DefaultListModel;
    Add a variable in your bean class.
    public IListModel model;
    initialize your model in your bean constructor method.
    public RfcBean () {
       model = new DefaultListModel();
    2. Modify your JSPDynpage code.
    table.beforeFirst();
      while(table.next()){
       bean.model.addItem(table.getString("column_1"),table.getString("column_1"));
    3. Modif your JSP code your dropdownlist box.
    <hbj:dropdownListBox
            id="List"
            model="<%=bean.model%>">
    </hbj:dropdownListBox>
    Message was edited by: Prakash  Singh

Maybe you are looking for