Elementtree tag

Discussion in 'Python' started by Sean DiZazzo, Dec 14, 2007.

  1. Sean DiZazzo

    Sean DiZazzo Guest

    I have a another question...

    using elementtree, is there a proper way to get at the data
    '123456789' in this tag?

    '<id 123456789 />'

    I tried making it an element, but the only attribute that returns
    anything is the "tag" attribute. Does that section of a tag have any
    proper name that I'm missing? Or is it just bad XML style?

    Thanks!

    ~Sean
     
    Sean DiZazzo, Dec 14, 2007
    #1
    1. Advertising

  2. On Dec 13, 7:52 pm, Sean DiZazzo <> wrote:
    > I have a another question...
    >
    > using elementtree, is there a proper way to get at the data
    > '123456789' in this tag?
    >
    > '<id 123456789 />'
    >
    > I tried making it an element, but the only attribute that returns
    > anything is the "tag" attribute. Does that section of a tag have any
    > proper name that I'm missing? Or is it just bad XML style?
    >

    It is not even legal xml.
    This may work.

    >>> from xml.etree import ElementTree as ET
    >>> elm = ET.fromstring('<atag id="123456789" />')
    >>> elm

    <Element atag at 1ba2f80>
    >>> elm.attrib

    {'id': '123456789'}
    >>>
     
    Waldemar Osuch, Dec 14, 2007
    #2
    1. Advertising

  3. Sean DiZazzo

    Sean DiZazzo Guest

    On Dec 13, 8:46 pm, Waldemar Osuch <> wrote:
    > On Dec 13, 7:52 pm, Sean DiZazzo <> wrote:> I have a another question...
    >
    > > using elementtree, is there a proper way to get at the data
    > > '123456789' in this tag?

    >
    > > '<id 123456789 />'

    >
    > > I tried making it an element, but the only attribute that returns
    > > anything is the "tag" attribute. Does that section of a tag have any
    > > proper name that I'm missing? Or is it just bad XML style?

    >
    > It is not even legal xml.
    > This may work.
    >
    > >>> from xml.etree import ElementTree as ET
    > >>> elm = ET.fromstring('<atag id="123456789" />')
    > >>> elm

    >
    > <Element atag at 1ba2f80>
    >
    > >>> elm.attrib

    > {'id': '123456789'}


    Thanks. I was afraid of that. Yet another hack for my code. argggh
     
    Sean DiZazzo, Dec 14, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shruds
    Replies:
    1
    Views:
    893
    John C. Bollinger
    Jan 27, 2006
  2. Damjan
    Replies:
    3
    Views:
    330
    Fredrik Lundh
    Mar 17, 2005
  3. Replies:
    4
    Views:
    333
    Carl Banks
    Sep 5, 2008
  4. Kee Nethery
    Replies:
    12
    Views:
    2,160
    Stefan Behnel
    Jun 27, 2009
  5. cmalmqui
    Replies:
    6
    Views:
    705
    Stefan Behnel
    Aug 12, 2009
Loading...

Share This Page