I could be given either of the following xml:
<?xml version="1.0" encoding="UTF-8"?>
<dc:video xmlns:dc="http://purl.org/dc/elements/1.1/">
<dc:title>
A vid with Pete
</dc:title>
<dc:description>
Petes vid
</dc:description>
<dc:contributor>
Pete
</dc:contributor>
<dc:subject>
Cat 2
</dc:subject>
</dc:video>
Or:
<?xml version="1.0" encoding="UTF-8"?>
<video>
<title>
A vid with Pete
<title>
<description>
Petes vid
<description>
<contributor>
Pete
<contributor>
<subject>
Cat 2
<subject>
</video>
Im trying to access an element:
string title = xmlDocFromOneLan.SelectSingleNode(@"/video/title").InnerXml;
But with xml document 1 it doesnt work due to the namespace.
Is there a way in c# to ignore the namespace using xpath? I simply want to select the node I really dont care about the namespace. (the namespace could be DC DN or DCN etc).
"/video"
would read:
<video></video>
or
<dc:video></video>
or
<dcn:video></video>
Yes, you can tell the XmlSerializer to ignore namespaces during de-serialization.
Once a namespace prefix is created, it cannot be changed or deleted. The workaround is to move all your code to a new Developer Organization, where you can setup the desired Namespace Prefix.
Remove namespaces using the Namespace Editor Determine the namespace for a node by selecting any object/node that uses the namespace. In the Namespace Editor, select the namespace you want to remove. Click Delete.
With XPath 1.0 all you can do is /*[local-name() = 'video']/*[local-name() = 'title']
. With XPath 2.0 you can use a wildcard /*:video/*:title
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With