get a xml node as-it-is

Discussion in 'XML' started by ArunDhaJ, Jan 17, 2008.

  1. ArunDhaJ

    ArunDhaJ Guest

    i hve a xml like this:
    <Students>
    <Student name = "arun1" number="6">
    <Student name = "arun2" number="7">
    <Student name = "arun3" number="8">
    <Student name = "arun4" number="9">
    ....
    ....
    ....
    </Students>

    i need to build a new xml or a string from this with few student
    nodes.... some thing like this..

    <Student>
    <Student name = "arun2" number="7">
    <Student name = "arun3" number="8">
    </Student>

    by selecting only the two nodes.........

    is there any api which should return some thing like this ????
    "<Student name = "arun2" number="7">"


    Thanks
    ArunDhaJ
     
    ArunDhaJ, Jan 17, 2008
    #1
    1. Advertising

  2. ArunDhaJ wrote:
    > i hve a xml like this:
    > <Students>
    > <Student name = "arun1" number="6">


    That is not well-formed, you need e.g.
    <Student name = "arun1" number="6"></Student>
    > <Student name = "arun2" number="7">
    > <Student name = "arun3" number="8">
    > <Student name = "arun4" number="9">
    > ...
    > ...
    > ...
    > </Students>
    >
    > i need to build a new xml or a string from this with few student
    > nodes.... some thing like this..
    >
    > <Student>
    > <Student name = "arun2" number="7">
    > <Student name = "arun3" number="8">
    > </Student>
    >
    > by selecting only the two nodes.........
    >
    > is there any api which should return some thing like this ????
    > "<Student name = "arun2" number="7">"


    Use an XSLT stylesheet for instance that copies what you want to copy:
    <xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:eek:utput method="xml"/>
    <xsl:template match="Students">
    <xsl:copy>
    <xsl:copy-of select="Student[@name = 'arun2' or @name = 'arun3']"/>
    </xsl:copy>
    </xsl:template>
    </xsl:stylesheet>

    You could as well use DOM programming to load the original document, the
    delete the Student elements you are not interested in and then save
    the DOM back.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jan 17, 2008
    #2
    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. wolf
    Replies:
    0
    Views:
    554
  2. Replies:
    0
    Views:
    1,465
  3. Tjerk Wolterink
    Replies:
    2
    Views:
    1,437
    Dimitre Novatchev
    Aug 24, 2006
  4. Martin Honnen

    Re: Reading XML Node-by-Node

    Martin Honnen, Nov 12, 2008, in forum: ASP .Net
    Replies:
    0
    Views:
    388
    Martin Honnen
    Nov 12, 2008
  5. Geagleeye

    how to creating new node inside a xml node

    Geagleeye, Aug 2, 2006, in forum: ASP General
    Replies:
    2
    Views:
    199
    Geagleeye
    Aug 3, 2006
Loading...

Share This Page