XML Parsing with Java.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    XML Parsing with Java.

    Hi Experts.
    I have a problem with XML parsing.
    Please Help!

    [code=xml]
    <?xml version="1.0" encoding="UTF-8"?>
    <XML>
    <Debasis>some_v alue</Debasis>
    <DmjPro>some_an other_value</DmjPro>
    <!--Some Comment-->
    <!--Some another comment-->
    <Saswati title="Mahapatr a" disignation="pr oject_member"></Saswati>
    <DebMou ID="my_id">some _value_saswati</DebMou>
    </XML>
    [/code]

    And my Java Code is:
    [code=java]
    Element el=doc.getEleme ntById("my_id") ;
    System.out.prin tln("DebMou_Nod e_value: "+el);
    [/code]

    Now the second line prints Null.
    Why?
    Please help.
    Is there any wrong format with XML?


    Kind regards,
    Dmjpro.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by dmjpro
    Hi Experts.
    I have a problem with XML parsing.
    Please Help!

    [code=xml]
    <?xml version="1.0" encoding="UTF-8"?>
    <XML>
    <Debasis>some_v alue</Debasis>
    <DmjPro>some_an other_value</DmjPro>
    <!--Some Comment-->
    <!--Some another comment-->
    <Saswati title="Mahapatr a" disignation="pr oject_member"></Saswati>
    <DebMou ID="my_id">some _value_saswati</DebMou>
    </XML>
    [/code]

    And my Java Code is:
    [code=java]
    Element el=doc.getEleme ntById("my_id") ;
    System.out.prin tln("DebMou_Nod e_value: "+el);
    [/code]

    Now the second line prints Null.
    Why?
    Please help.
    Is there any wrong format with XML?


    Kind regards,
    Dmjpro.
    Can you post the full code you used for this?

    Comment

    • dmjpro
      Top Contributor
      • Jan 2007
      • 2476

      #3
      Originally posted by r035198x
      Can you post the full code you used for this?
      This is my full Java Code.

      [code=java]
      DocumentBuilder d = DocumentBuilder Factory.newInst ance().newDocum entBuilder();
      Document doc = d.parse(new File("c:/Test.xml"));
      Element el=doc.getEleme ntById("my_id") ;
      System.out.prin tln("DebMou_Nod e_value: "+el);
      [/code]

      Now I think you will be able to solve my problem?
      And Thanks for reply me.

      Kind regards,
      Dmjpro.

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by dmjpro
        This is my full Java Code.

        [code=java]
        DocumentBuilder d = DocumentBuilder Factory.newInst ance().newDocum entBuilder();
        Document doc = d.parse(new File("c:/Test.xml"));
        Element el=doc.getEleme ntById("my_id") ;
        System.out.prin tln("DebMou_Nod e_value: "+el);
        [/code]

        Now I think you will be able to solve my problem?
        And Thanks for reply me.

        Kind regards,
        Dmjpro.
        Use getelementByTag Name to get the required elements.

        See the docs for what's required for you to be able to use getElementByID

        Comment

        • dmjpro
          Top Contributor
          • Jan 2007
          • 2476

          #5
          Originally posted by r035198x
          Use getelementByTag Name to get the required elements.

          See the docs for what's required for you to be able to use getElementByID
          I already had a look at those Docs.
          But I could not find any Error in XML file.
          That's why i come here.
          But I want to know what is the problem with getElementById( )?
          I know it can be solved using getElementsbyTa gName().
          Please help to solve this problem using getElementById( ).

          Kind regards,
          Dmjpro.

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by dmjpro
            I already had a look at those Docs.
            But I could not find any Error in XML file.
            That's why i come here.
            But I want to know what is the problem with getElementById( )?
            I know it can be solved using getElementsbyTa gName().
            Please help to solve this problem using getElementById( ).

            Kind regards,
            Dmjpro.
            Did you read the docs entry for getElementById like I said? It tells you why you got the value as null and when you can use it.

            Comment

            • dmjpro
              Top Contributor
              • Jan 2007
              • 2476

              #7
              Originally posted by r035198x
              Did you read the docs entry for getElementById like I said? It tells you why you got the value as null and when you can use it.
              Could you help me please?
              I can't get what's the Error with my XML file.
              Please help.

              Kind regards,
              Dmjpro.

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                Originally posted by dmjpro
                Could you help me please?
                I can't get what's the Error with my XML file.
                Please help.

                Kind regards,
                Dmjpro.
                From the docs that you claim to have read
                " ... The DOM implementation must have information that says which attributes are of type ID. Attributes with the name "ID" are not of type ID unless so defined. Implementations that do not know whether attributes are of type ID or not are expected to return null. "

                Comment

                • JosAH
                  Recognized Expert MVP
                  • Mar 2007
                  • 11453

                  #9
                  Originally posted by r035198x
                  From the docs that you claim to have read
                  " ... The DOM implementation must have information that says which attributes are of type ID. Attributes with the name "ID" are not of type ID unless so defined. Implementations that do not know whether attributes are of type ID or not are expected to return null. "
                  Ah! reading! That ancient lost artform; this is the copy/paste age, people can't
                  read anymore. Reading wastes time; better ask vague questions everywhere
                  and hope that someone supplies you with the stuff to be copied and pasted.
                  Let other's waste their time; who cares.

                  If it works; fine; who cares *why* it works anyway? If it doesn't, come back and
                  complain; if no new copyable/pasteable replies follow; so be it. If they do: rinse
                  and repeat. What a beautiful 'information' society we live in.

                  I plea for the following software development methodology: there are two buildings:
                  one luxury building with all the fun and luxury but *no* development environments
                  there. Internet connections: yes; comfy chairs: yes; an abundance of coffee etc.:
                  yes; but no compilers, no debuggers, no nothing of the sort. A lot of pencils and
                  paper: yes.

                  When the software has been designed one has to migrate to that other building
                  where a lot of compilers, fast computers, debuggers etc. are available. But no
                  coffee, no internet connections, no comfy chairs, no nothing.

                  One is not allowed to leave that building until the designed software has been
                  implemented. That should teach those lazy analphabetic bums to read their own
                  notes, to read what those compilers have to tell them; to read runtime error
                  messages etc. Otherwise they're never allowed to leave that boring second building.

                  kind regards,

                  Jos

                  Comment

                  • r035198x
                    MVP
                    • Sep 2006
                    • 13225

                    #10
                    Originally posted by JosAH
                    Ah! reading! That ancient lost artform; this is the copy/paste age, people can't
                    read anymore. Reading wastes time; better ask vague questions everywhere
                    and hope that someone supplies you with the stuff to be copied and pasted.
                    Let other's waste their time; who cares.

                    If it works; fine; who cares *why* it works anyway? If it doesn't, come back and
                    complain; if no new copyable/pasteable replies follow; so be it. If they do: rinse
                    and repeat. What a beautiful 'information' society we live in.

                    I plea for the following software development methodology: there are two buildings:
                    one luxury building with all the fun and luxury but *no* development environments
                    there. Internet connections: yes; comfy chairs: yes; an abundance of coffee etc.:
                    yes; but no compilers, no debuggers, no nothing of the sort. A lot of pencils and
                    paper: yes.

                    When the software has been designed one has to migrate to that other building
                    where a lot of compilers, fast computers, debuggers etc. are available. But no
                    coffee, no internet connections, no comfy chairs, no nothing.

                    One is not allowed to leave that building until the designed software has been
                    implemented. That should teach those lazy analphabetic bums to read their own
                    notes, to read what those compilers have to tell them; to read runtime error
                    messages etc. Otherwise they're never allowed to leave that boring second building.

                    kind regards,

                    Jos
                    Which building has the better pay?

                    Comment

                    • dmjpro
                      Top Contributor
                      • Jan 2007
                      • 2476

                      #11
                      Originally posted by JosAH
                      Ah! reading! That ancient lost artform; this is the copy/paste age, people can't
                      read anymore. Reading wastes time; better ask vague questions everywhere
                      and hope that someone supplies you with the stuff to be copied and pasted.
                      Let other's waste their time; who cares.

                      If it works; fine; who cares *why* it works anyway? If it doesn't, come back and
                      complain; if no new copyable/pasteable replies follow; so be it. If they do: rinse
                      and repeat. What a beautiful 'information' society we live in.

                      I plea for the following software development methodology: there are two buildings:
                      one luxury building with all the fun and luxury but *no* development environments
                      there. Internet connections: yes; comfy chairs: yes; an abundance of coffee etc.:
                      yes; but no compilers, no debuggers, no nothing of the sort. A lot of pencils and
                      paper: yes.

                      When the software has been designed one has to migrate to that other building
                      where a lot of compilers, fast computers, debuggers etc. are available. But no
                      coffee, no internet connections, no comfy chairs, no nothing.

                      One is not allowed to leave that building until the designed software has been
                      implemented. That should teach those lazy analphabetic bums to read their own
                      notes, to read what those compilers have to tell them; to read runtime error
                      messages etc. Otherwise they're never allowed to leave that boring second building.

                      kind regards,

                      Jos
                      Again impressive.
                      Really I am sorry Jos.
                      That I didn't read carefully what rox told me to read.
                      But I saw he just made bold the main line nothing changes was there then I understood.
                      Anyway, thanks for saying thing ... I always prefer the second building.
                      The R&D building.
                      I think you did a lot of hard works.
                      That's you mentality is such ..... Different.
                      Anyway, Best of Luck with your life whatever you are doing.

                      Kind regards,
                      Dmjpro

                      Comment

                      Working...