Namespace xml extract -- help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mag Gam

    #1

    Namespace xml extract -- help

    I have a file similar to this:

    <Customer xmlns="http://www.localsite.c om/ecommerce/2006-v01/
    organization">
    <ns1:Contract xmlns:ns1="http ://www.localsite.c om/ecommerce/2006-v01/
    portfolio">
    <ns1:ContractId >
    <ns2:Identifi er xmlns:ns2="http ://www.localsite.c om/ecommerce/2006-
    v01/common">199</ns2:Identifier>
    </ns1:ContractId>
    <ns1:Organizati onId>
    <ns3:Identifi er xmlns:ns3="http ://www.localsite.c om/ecommerce/2006-
    v01/common">6142</ns3:Identifier>
    </ns1:Organizatio nId>
    </ns1:Contract>
    </Customer>

    How can I extract, Identifier field's data?

    It seems I am not able to extract using DOM, because of Namespaces.
    Any help would be appreciated.

    TIA

  • Joe Kesselman

    #2
    Re: Namespace xml extract -- help

    Mag Gam wrote:
    It seems I am not able to extract using DOM, because of Namespaces.
    It seems you aren't doing your homework.

    DOM Level 2 and later are fully namespace-aware, if built using the
    namespace-aware APIs and/or a namespace-aware parser. Look at any decent
    DOM tutorial. If you don't understand namespaces, look at a good XML
    tutorial as well.





    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry

    Comment

    • Mag Gam

      #3
      Re: Namespace xml extract -- help

      On Mar 3, 8:38 pm, Joe Kesselman <keshlam-nos...@comcast. netwrote:
      Mag Gam wrote:
      It seems I am not able to extract using DOM, because of Namespaces.
      >
      It seems you aren't doing your homework.
      >
      DOM Level 2 and later are fully namespace-aware, if built using the
      namespace-aware APIs and/or a namespace-aware parser. Look at any decent
      DOM tutorial. If you don't understand namespaces, look at a good XML
      tutorial as well.
      >
      --
      () ASCII Ribbon Campaign | Joe Kesselman
      /\ Stamp out HTML e-mail! | System architexture and kinetic poetry

      Thanks! As long as I am on the right track I should do well. For
      Namespaces, I will use http://www.w3schools.com/xml/xml_namespaces.asp
      and http://www.w3schools.com/dom/dom_examples.asp

      Thanks again!

      Comment

      • Joe Kesselman

        #4
        Re: Namespace xml extract -- help

        Mag Gam wrote:
        Thanks! As long as I am on the right track I should do well. For
        Namespaces, I will use http://www.w3schools.com/xml/xml_namespaces.asp
        and http://www.w3schools.com/dom/dom_examples.asp
        I did say find a *good* tutorial. Unfortunately that isn't one.

        The DOM examples they show are obsolete; they use the DOM Level 1
        non-namespaced create-element method, for example, which isn't
        compatable with namespace-aware processing. These days you shouldn't
        touch createElement() ; you should only be using createElementNS (). Ditto
        for other methods replaced by ...NS() versions.


        Yes, I admit, this is partly the DOM WG's fault for not clearly
        deprecating the old non-NS calls. We wanted to do so, but we got a huge
        amount of pushback from folks who pointed out that the old calls were
        still legitimate for (and ONLY for) backward-compatability with
        pre-existing DOM Level 1 code. The best agreement we could get from them
        was agreement that the DOM Level 2 spec should include a warning ... but
        not enough people actually read the spec. Growl.

        --
        () ASCII Ribbon Campaign | Joe Kesselman
        /\ Stamp out HTML e-mail! | System architexture and kinetic poetry

        Comment

        • =?ISO-8859-1?Q?Une_B=E9vue?=

          #5
          Re: Namespace xml extract -- help

          Joe Kesselman <keshlam-nospam@comcast. netwrote:
          >
          I did say find a *good* tutorial. Unfortunately that isn't one.
          U know of >>>GOOD-GOD<<< links ?

          ;-)
          --
          Une Bévue

          Comment

          • Mag Gam

            #6
            Re: Namespace xml extract -- help

            On Mar 4, 12:19 am, unbewusst.s...@ google.com.inva lid (Une Bévue)
            wrote:
            Joe Kesselman <keshlam-nos...@comcast. netwrote:
            >
            I did say find a *good* tutorial. Unfortunately that isn't one.
            >
            U know of >>>GOOD-GOD<<< links ?
            >
            ;-)
            --
            Une Bévue
            Yes, do you know of any links?

            Comment

            • Martin Honnen

              #7
              Re: Namespace xml extract -- help

              Mag Gam wrote:
              I have a file similar to this:
              >
              <Customer xmlns="http://www.localsite.c om/ecommerce/2006-v01/
              organization">
              <ns1:Contract xmlns:ns1="http ://www.localsite.c om/ecommerce/2006-v01/
              portfolio">
              <ns1:ContractId >
              <ns2:Identifi er xmlns:ns2="http ://www.localsite.c om/ecommerce/2006-
              v01/common">199</ns2:Identifier>
              </ns1:ContractId>
              <ns1:Organizati onId>
              <ns3:Identifi er xmlns:ns3="http ://www.localsite.c om/ecommerce/2006-
              v01/common">6142</ns3:Identifier>
              </ns1:Organizatio nId>
              </ns1:Contract>
              </Customer>
              >
              How can I extract, Identifier field's data?
              Here is JavaScript that runs in W3C DOM Level 2 compliant browsers like
              Mozilla or like Opera:

              var identifiers =
              xmlDocument.get ElementsByTagNa meNS('http://www.localsite.c om/ecommerce/2006-v01/common',
              'Identifier');
              for (var i = 0, l = identifiers.len gth; i < l; i++) {
              alert(identifie rs[i].firstChild.nod eValue);
              }

              You could for instance load the XML document with XMLHttpRequest.


              --

              Martin Honnen
              http://JavaScript.FAQTs.com/

              Comment

              • Joe Kesselman

                #8
                Re: Namespace xml extract -- help

                Yes, do you know of any links?

                I've been generally (not completely) pleased with the material that gets
                posted at http://www.ibm.com/xml.

                --
                () ASCII Ribbon Campaign | Joe Kesselman
                /\ Stamp out HTML e-mail! | System architexture and kinetic poetry

                Comment

                Working...