XML Problem mediawiki

pitaridis

Well-known member
Joined
Nov 18, 2005
Messages
63
Programming Experience
10+
I have the following xml file:

VB.NET:
<mediawiki xmlns="[URL]http://www.mediawiki.org/xml/export-0.3/[/URL]" 
xmlns:xsi="[URL]http://www.w3.org/2001/XMLSchema-instance[/URL]" 
xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.3[URL="http://www.mediawiki.org/xml/export-0.3.xsd"].xsd[/URL]" 
version="0.3" xml:lang="en">
<siteinfo>
<sitename>Wikipedia</sitename>
<base>http://en.wikipedia.org/wiki/Main_Page</base>
<generator>MediaWiki 1.9alpha</generator>
<case>first-letter</case>
<namespaces>
<namespace key="-2">Media</namespace>
<namespace key="-1">Special</namespace>
<namespace key="0" />
<namespace key="1">Talk</namespace>
<namespace key="2">User</namespace>
<namespace key="3">User talk</namespace>
<namespace key="4">Wikipedia</namespace>
<namespace key="5">Wikipedia talk</namespace>
<namespace key="6">Image</namespace>
<namespace key="7">Image talk</namespace>
<namespace key="8">MediaWiki</namespace>
<namespace key="9">MediaWiki talk</namespace>
<namespace key="10">Template</namespace>
<namespace key="11">Template talk</namespace>
<namespace key="12">Help</namespace>
<namespace key="13">Help talk</namespace>
<namespace key="14">Category</namespace>
<namespace key="15">Category talk</namespace>
<namespace key="100">Portal</namespace>
<namespace key="101">Portal talk</namespace>
</namespaces>
</siteinfo>
<page>
<title>Play</title>
<id>22962</id>
<revision>
<id>79448292</id>
<timestamp>2006-10-04T13:00:19Z</timestamp>
<contributor>
<username>JonHarder</username>
<id>629503</id>
</contributor>
<comment>revert: not seeing why this article should be exempt from citing sources.</comment>
[B]<text xml:space="preserve">Plays are written in a variety of genres.</text>[/B]
</revision>
</page>
</mediawiki>
I want to read the contents of the text (The bold part). I use the following code but it does not work
VB.NET:
[SIZE=2]Doc.Load([/SIZE][SIZE=2][COLOR=#800000]"http://en.wikipedia.org/wiki/Special:Export/test"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] Doc.SelectNodes([/SIZE][SIZE=2][COLOR=#800000]"/mediawiki/page/revision/text"[/COLOR][/SIZE][SIZE=2]).Count > 0 [/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] output [/SIZE][SIZE=2][COLOR=#0000ff]As   [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = Doc.SelectNodes([/SIZE][SIZE=2][COLOR=#800000]"/mediawiki/page/revision/text"[/COLOR][/SIZE][SIZE=2]).Item(0).InnerText[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]End  [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[/COLOR][/SIZE]
Can someone tell me what is wrong with my code or if there is an other way to get the text value

Aristotelis
 
Last edited by a moderator:
I found that the return Xml specifies its own xmlns namespace, adding this to a NamespaceManager with some prefix works. Example:
VB.NET:
[SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] mediawiki()
[/SIZE][SIZE=2][COLOR=#0000ff] Dim[/COLOR][/SIZE][SIZE=2] doc [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Xml.XmlDocument
 doc.Load([/SIZE][SIZE=2][COLOR=#800000]"http://en.wikipedia.org/wiki/Special:Export/test"[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff] Dim[/COLOR][/SIZE][SIZE=2] nm [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Xml.XmlNamespaceManager(doc.NameTable)
 nm.AddNamespace([/SIZE][SIZE=2][COLOR=#800000]"m"[/COLOR][/SIZE][SIZE=2], doc.DocumentElement.NamespaceURI)
[/SIZE][SIZE=2][COLOR=#0000ff] Dim[/COLOR][/SIZE][SIZE=2] xnl [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Xml.XmlNodeList = doc.SelectNodes([/SIZE][SIZE=2][COLOR=#800000]"/m:mediawiki/m:page/m:revision/m:text"[/COLOR][/SIZE][SIZE=2], nm)
[/SIZE][SIZE=2][COLOR=#0000ff] If[/COLOR][/SIZE][SIZE=2] xnl.Count > 0 [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]  MsgBox(xnl.Item(0).InnerText)
[/SIZE][SIZE=2][COLOR=#0000ff] End [/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE]
 
Back
Top