Change
ns.AddNamespace("ns", "xmlns=""http://someserver/somewhere""")
to
ns.AddNamespace("ns", "http://someserver/somewhere")
the "xmlns=" is Not part of the URI, the prefix "ns" should map to
"http://someserver/somewhere"
--
This posting is provided "AS IS" with no warranties, and confers no rights.
[quoted text, click to view] "John Lucas" <cab0san@hotmail.com> wrote in message
news:22f0094b.0404290444.5d410b89@posting.google.com...
> That didn't work. xnode is still Nothing.
>
> "Yan Leshinsky" <yanl@online.microsoft.com> wrote in message
news:<e8hSA6aLEHA.1392@TK2MSFTNGP09.phx.gbl>...
> > Try
> > xnode = doc.SelectSingleNode("/ns:catalog/ns:cd/ns:price", ns)
> >
> >
> > "John Lucas" <cab0san@hotmail.com> wrote in message
> > news:22f0094b.0404282140.e70e9d9@posting.google.com...
> > > I'm new to this, so I've been reading about namespaces and xpath
> > > queries.
> > >
> > > I am trying to write a dotnet program that will change the value of a
> > > node. I am getting the file from another vendor, so I can't control
> > > the format.
> > >
> > > Here's a sample
> > >
> > > ============================================================
> > >
> > > <?xml version="1.0" encoding="utf-8"?>
> > > <catalog xmlns="http://someserver/somewhere"
> > > xmlns:ab="http://anotherserver/rightthere">
> > > <cd country="USA">
> > > <title>Reason</title>
> > > <artist>Capital 8</artist>
> > > <price>9.99</price>
> > > </cd>
> > > <cd country="USA">
> > > <title>Yoshimi Battles The Pink Robots</title>
> > > <artist>The Flaming Lips</artist>
> > > <price>15.99</price>
> > > </cd>
> > > <cd country="USA">
> > > <title>Nugget</title>
> > > <artist>Cake</artist>
> > > <price>12.99</price>
> > > </cd>
> > > <cd country="USA">
> > > <title>Under The Cold Blue Stars</title>
> > > <artist>Josh Rouse</artist>
> > > <price>13.00</price>
> > > </cd>
> > > </catalog>
> > >
> > > ============================================================
> > >
> > > Dim doc As New System.Xml.XmlDocument
> > > Dim fName As String = "c:\temp\test.xml"
> > > doc.Load(fName)
> > > Dim ns As New XmlNamespaceManager(doc.NameTable)
> > > ns.AddNamespace("ns", "xmlns=""http://someserver/somewhere""")
> > > ' (also tried ns.AddNamespace("",
> > > xmlns=""http://someserver/somewhere""")
> > > ns.AddNamespace("ab", "xmlns:ab=""http://anotherserver/rightthere""")
> > >
> > > Dim xnode As XmlNode
> > >
> > > ' Let's say I want to change the price of the first cd
> > >
> > > xnode = doc.SelectSingleNode("/ns:catalog/cd/price", ns)
> > >
> > > xnode.InnerXml = "1"
> > >
> > > doc.save(fName + ".new.xml")
> > >
> > > SelectSingleNode never seems to work unless I ignore namespaces
> > > (using an xmltextreader.namespaces=false).
> > >
> > > What is the correct xpath syntax for that?