Replacing an XML element?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nick Vargish

    #1

    Replacing an XML element?

    I've been trying to figure out how to do something that seems
    relatively simple, but it's just not coming together for me. I'm
    hoping someone will deign to give me a little insight here.

    The problem: We have XML documents that use a custom table format that
    was designed primarily for typesetting documents. It's a column-first
    oriented scheme, and now we need a way to convert these table elements
    to HTML style row-first tables.

    I would like to be able to do something like this:

    doc = xml.dom.minidom .parse(input)
    for table in doc.getElements ByTagName('COLT ABLE'):
    newtable = coltable_to_row table(table)
    ## this is what I can't figure out
    doc.replace(tab le, newtable)
    output.write(do c.toxml('utf-8'))

    I'm pretty sure I'm missing something obvious, but haven't been able
    to find any examples.

    Someone please whack me with a cluestick,

    Nick

    --
    #include<stdio. h> /* sigmask (sig.c) 20041028 PUBLIC DOMAIN */
    int main(c,v)char *v;{return !c?putchar(* /* cc -o sig sig.c */
    v-1)&&main(0,v+1) :main(0,"Ojdl!W bshjti!=ojdlAwb shjti/psh?\v\1");}
  • Max Erickson

    #2
    Re: Replacing an XML element?

    Nick Vargish <nav+posts@band ersnatch.org> wrote in
    news:87wtlbdfo4 .fsf@localhost. localdomain:
    [color=blue]
    > I've been trying to figure out how to do something that seems
    > relatively simple, but it's just not coming together for me. I'm
    > hoping someone will deign to give me a little insight here.
    >
    > The problem: We have XML documents that use a custom table format
    > that was designed primarily for typesetting documents. It's a
    > column-first oriented scheme, and now we need a way to convert
    > these table elements to HTML style row-first tables.
    >
    > I would like to be able to do something like this:
    >
    > doc = xml.dom.minidom .parse(input)
    > for table in doc.getElements ByTagName('COLT ABLE'):
    > newtable = coltable_to_row table(table)
    > ## this is what I can't figure out
    > doc.replace(tab le, newtable)
    > output.write(do c.toxml('utf-8'))
    >
    > I'm pretty sure I'm missing something obvious, but haven't been
    > able to find any examples.
    >
    > Someone please whack me with a cluestick,
    >
    > Nick
    >[/color]

    table.parentNod e.replaceChild( newtable, table)

    Comment

    • Nick Vargish

      #3
      Re: Replacing an XML element?

      Max Erickson <maxerickson@gm ail.com> writes:
      [color=blue]
      > table.parentNod e.replaceChild( newtable, table)[/color]

      I knew it had to be something simple (but not as simple as I am,
      apparently :^).

      Thanks much, Max, you've saved the rest of my day.

      Nick

      --
      #include<stdio. h> /* sigmask (sig.c) 20041028 PUBLIC DOMAIN */
      int main(c,v)char *v;{return !c?putchar(* /* cc -o sig sig.c */
      v-1)&&main(0,v+1) :main(0,"Ojdl!W bshjti!=ojdlAwb shjti/psh?\v\1");}

      Comment

      Working...