Extract a <node> as a new XMLDocument?

Discussion in 'ASP .Net' started by Carlos Albert, Jan 19, 2006.

  1. Hello,

    Would you tell me if there is a way to extract a single node as a new
    xmldocument?

    Thanks.
     
    Carlos Albert, Jan 19, 2006
    #1
    1. Advertising

  2. Carlos,
    You would need to :
    1) Create a new XmlDocument.
    2) use the ImportNode method to bring in the node from the other XmlDocument.

    See MSDN Library Help or online for code samples.

    Peter

    --
    Co-founder, Eggheadcafe.com developer portal:
    http://www.eggheadcafe.com
    UnBlog:
    http://petesbloggerama.blogspot.com




    "Carlos Albert" wrote:

    > Hello,
    >
    > Would you tell me if there is a way to extract a single node as a new
    > xmldocument?
    >
    > Thanks.
    >
    >
    >
     
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Jan 19, 2006
    #2
    1. Advertising

  3. Tnx, but I tried to do this and I'm doing something very wrong (cause it
    doesn't work at all):

    Dim big_xml As New XmlDocument

    big_xml.LoadXml(xml)

    Dim small_xml As New XmlDocument

    Dim result As XmlNode =
    small_xml.ImportNode(big_xml.GetElementsByTagName("node_tag_name").Item(0),
    True)

    small_xml.DocumentElement.AppendChild(result)



    "Peter Bromberg [C# MVP]" <> wrote in message
    news:...
    > Carlos,
    > You would need to :
    > 1) Create a new XmlDocument.
    > 2) use the ImportNode method to bring in the node from the other
    > XmlDocument.
    >
    > See MSDN Library Help or online for code samples.
    >
    > Peter
    >
    > --
    > Co-founder, Eggheadcafe.com developer portal:
    > http://www.eggheadcafe.com
    > UnBlog:
    > http://petesbloggerama.blogspot.com
    >
    >
    >
    >
    > "Carlos Albert" wrote:
    >
    >> Hello,
    >>
    >> Would you tell me if there is a way to extract a single node as a new
    >> xmldocument?
    >>
    >> Thanks.
    >>
    >>
    >>
     
    Carlos Albert, Jan 19, 2006
    #3
  4. Break up your code into smaller pieces so it's easier to see what is happening
    on each line with debugger step-through.
    Also, ensure the new document has the correct processing instruction, root
    element, etc. to be valid.
    Also, it looks to me like you are trying to import your node from the new
    document instead of the original!

    Peter

    --
    Co-founder, Eggheadcafe.com developer portal:
    http://www.eggheadcafe.com
    UnBlog:
    http://petesbloggerama.blogspot.com




    "Carlos Albert" wrote:

    > Tnx, but I tried to do this and I'm doing something very wrong (cause it
    > doesn't work at all):
    >
    > Dim big_xml As New XmlDocument
    >
    > big_xml.LoadXml(xml)
    >
    > Dim small_xml As New XmlDocument
    >
    > Dim result As XmlNode =
    > small_xml.ImportNode(big_xml.GetElementsByTagName("node_tag_name").Item(0),
    > True)
    >
    > small_xml.DocumentElement.AppendChild(result)
    >
    >
    >
    > "Peter Bromberg [C# MVP]" <> wrote in message
    > news:...
    > > Carlos,
    > > You would need to :
    > > 1) Create a new XmlDocument.
    > > 2) use the ImportNode method to bring in the node from the other
    > > XmlDocument.
    > >
    > > See MSDN Library Help or online for code samples.
    > >
    > > Peter
    > >
    > > --
    > > Co-founder, Eggheadcafe.com developer portal:
    > > http://www.eggheadcafe.com
    > > UnBlog:
    > > http://petesbloggerama.blogspot.com
    > >
    > >
    > >
    > >
    > > "Carlos Albert" wrote:
    > >
    > >> Hello,
    > >>
    > >> Would you tell me if there is a way to extract a single node as a new
    > >> xmldocument?
    > >>
    > >> Thanks.
    > >>
    > >>
    > >>

    >
    >
    >
     
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Jan 19, 2006
    #4
  5. Made it work, thanks! =)

    Dim big_xml As New XmlDocument
    big_xml.LoadXml(xml)
    Dim small_xml As New XmlDocument
    Dim result As XmlNode
    result =
    small_xml.ImportNode(big_xml.GetElementsByTagName("small_xml").Item(0),
    True)
    small_xml.LoadXml("<small_xml>" & result.InnerXml & "</small_xml>")


    "Peter Bromberg [C# MVP]" <> wrote in message
    news:...
    > Break up your code into smaller pieces so it's easier to see what is
    > happening
    > on each line with debugger step-through.
    > Also, ensure the new document has the correct processing instruction, root
    > element, etc. to be valid.
    > Also, it looks to me like you are trying to import your node from the new
    > document instead of the original!
    >
    > Peter
    >
    > --
    > Co-founder, Eggheadcafe.com developer portal:
    > http://www.eggheadcafe.com
    > UnBlog:
    > http://petesbloggerama.blogspot.com
    >
    >
    >
    >
    > "Carlos Albert" wrote:
    >
    >> Tnx, but I tried to do this and I'm doing something very wrong (cause it
    >> doesn't work at all):
    >>
    >> Dim big_xml As New XmlDocument
    >>
    >> big_xml.LoadXml(xml)
    >>
    >> Dim small_xml As New XmlDocument
    >>
    >> Dim result As XmlNode =
    >> small_xml.ImportNode(big_xml.GetElementsByTagName("node_tag_name").Item(0),
    >> True)
    >>
    >> small_xml.DocumentElement.AppendChild(result)
    >>
    >>
    >>
    >> "Peter Bromberg [C# MVP]" <> wrote in
    >> message
    >> news:...
    >> > Carlos,
    >> > You would need to :
    >> > 1) Create a new XmlDocument.
    >> > 2) use the ImportNode method to bring in the node from the other
    >> > XmlDocument.
    >> >
    >> > See MSDN Library Help or online for code samples.
    >> >
    >> > Peter
    >> >
    >> > --
    >> > Co-founder, Eggheadcafe.com developer portal:
    >> > http://www.eggheadcafe.com
    >> > UnBlog:
    >> > http://petesbloggerama.blogspot.com
    >> >
    >> >
    >> >
    >> >
    >> > "Carlos Albert" wrote:
    >> >
    >> >> Hello,
    >> >>
    >> >> Would you tell me if there is a way to extract a single node as a new
    >> >> xmldocument?
    >> >>
    >> >> Thanks.
    >> >>
    >> >>
    >> >>

    >>
    >>
    >>
     
    Carlos Albert, Jan 20, 2006
    #5
    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. Replies:
    0
    Views:
    1,587
  2. Shoval Tomer
    Replies:
    0
    Views:
    457
    Shoval Tomer
    Jul 9, 2003
  3. Bob
    Replies:
    0
    Views:
    420
  4. Casper B
    Replies:
    1
    Views:
    1,296
    Stanimir Stamenkov
    Jan 29, 2005
  5. Tjerk Wolterink
    Replies:
    2
    Views:
    1,467
    Dimitre Novatchev
    Aug 24, 2006
Loading...

Share This Page