Paul,
If you always want all the child nodes of the selected menu element,
it is pretty straightforward. The one thing you need to do that is
not obvious is using import node. Also it looks like your current
code for building the second XML document is working on the original
xmlDoc. Also remember xpath is case-sensitive. What I'd do...
'create new doc and its root nood
Dim xmlSubMenu As XmlDocument = New XmlDocument
Dim rootNode As XmlElement = xmlSubMenu.CreateElement("menu")
xmlSubMenu.AppendChild(rootNode)
Dim strMenuItemText As String = "Settlement" '-- Hardcoded here
Dim myXPath As String =
String.Format("/menu/menuItem[text='{0}']/subMenu", strMenuItemText)
'this should point to subMenu node for Settlement menuitem if the
Xpath is right
xmlNode = menuXML.SelectSingleNode(myXPath)
'get child nodes and add them into the the new doc.
dim nChild as XmlNode
Dim nChildForNew as XmlNode
for each nChild in xmlNode.ChildNodes
nChildForNew = xmlSubMenu.ImportNode(nChild, true)
rootNode.AppendChild(nChildForNew)
next
that should be all there is to it.
On 7/18/05, Paul N. Chu <[EMAIL PROTECTED]> wrote:
> Here's is the basic code I have so far:
>
> '-- Build Top Full Horizontal Menu at Menu1 server control
> Dim menuXML As New System.Xml.XmlDocument
> Dim xmlNode As System.Xml.XmlNode
> menuXML.Load(Server.MapPath("CoStar.xml")) ' the Menu file
> Menu1.DataSource = menuXML
> Menu1.DataBind() ' Top Horiz Menu built
>
> '-- Build SubMenu Menu at Menu2 server control
> Dim xmlSubMenu As XmlDocument = New XmlDocument
> Dim xmlDeclaration As XmlDeclaration =
> xmlDoc.CreateXmlDeclaration("1.0", "utf-8", Nothing)
> Dim rootNode As XmlElement = xmlDoc.CreateElement("Menu")
> xmlDoc.InsertBefore(xmlDeclaration, xmlDoc.DocumentElement)
> xmlDoc.AppendChild(rootNode)
>
> Dim strMenuItemText As String = "Settlement" '-- Hardcoded here
> Dim myXPath As String =
> String.Format("/menu/menuItem[text='{0}']/subMenu", strMenuItemText)
>
> 'this should point to subMenu node for Settlement menuitem if the
> Xpath is right
> xmlNode = menuXML.SelectSingleNode(myXPath)
>
> ' ??? How to collect all the childNodes and copy to new document
> ' xmlNode.childNodes loop ? with appendChild etc ?
>
> Menu2.DataSource = xmlSubMenu
> Menu2.DataBind()
>
>
> On 7/18/05, Paul N. Chu <[EMAIL PROTECTED]> wrote:
> > Given the following xml , I would like to XPATH for the Placement or
> > Settlement menuitem and then construct another XML file shown below
> > from the childnodes of the subMenu node.
> >
> > <menu>
> > <menuItem>
> > <text>Placement</text>
> > <cssclass>highlighteditem</cssclass>
> > <subMenu>
> > <menuItem>
> > <text>Sub Item 3</text>
> > <url>page3.html</url>
> > </menuItem>
> > <menuItem>
> > <text>Sub Item 4</text>
> > <url>page4.html</url>
> > </menuItem>
> > </subMenu>
> > </menuItem>
> >
> > <menuItem>
> > <text>Settlement</text>
> > <cssclass>highlighteditem</cssclass>
> > <subMenu>
> > <menuItem>
> > <text>Sub Item 3</text>
> > <url>page3.html</url>
> > </menuItem>
> > <menuItem>
> > <text>Sub Item 4</text>
> > <url>page4.html</url>
> > </menuItem>
> > </subMenu>
> > </menuItem>
> > </menu>
> >
> >
> > This is the desired submenu xml that I would like to create:
> >
> > <menu>
> > <menuItem>
> > <text>Sub Item 3</text>
> > <url>page3.html</url>
> > </menuItem>
> > <menuItem>
> > <text>Sub Item 4</text>
> > <url>page4.html</url>
> > </menuItem>
> > </menu>
> >
> > Thanks, Paul
> >
> > On 7/18/05, getsmartpaul86 <[EMAIL PROTECTED]> wrote:
> > > Hi Xmlers,
> > >
> > > I'm looking for an example that would
> > > use xpath to search a document for a Node and then
> > > clone / copy that node and it's children to another xmldocument.
> > >
> > > I'm working with skmMenu by Scott Mitchell and have a Horizontal Top
> > > Menu and would like to search the menu xml nodes to find
> > > the current Top Level Menu and copy it's children
> > > and then show those nodes also in a left hand - navigation menu.
> > >
> > > Thus if the top menu has CatA , CatB, CatC
> > > then the xpath to CatB
> > > would find all the childnodes of CatB and then copy them
> > > to a new XML document.
> > >
> > > Thanks for your help, Paul
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > Yahoo! Groups Links
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> >
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>
--
Dean Fiala
Very Practical Software, Inc
http://www.vpsw.com
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/