Reputation: 125
I have xml file with this codes:
<?xml version='1.0' encoding='utf-8'?>
<widget id="PACKAGE_NAME" version="PROJECT_VERSION" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
<name>PROJECT_NAME</name>
<preference name="android-minSdkVersion" value="MIN_SDK" />
<preference name="android-versionCode" value="VERSION_CODE" />
<preference name="android-installLocation" value="INSTALL" />
<preference name="android-targetSdkVersion" value="TARGET_SDK" />
<preference name="orientation" value="ORIENTATION" />
<preference name="fullscreen" value="FULLSCREEN" />
</widget>
And i have this variables:
Dim PackageName, ProjectName, ProjectVersion, VersionCode, MinSdk, TargetSdk, InstallLocation, Orientation, FullScreen As String
I use this code to get ProjectName, PackageName and ProjectVersion:
Dim doc as XmlDocument = new XmlDocument()
doc.Load("config.xml")
Dim root As XmlElement = doc.DocumentElement
PackageName = root.GetAttribute("id")
ProjectVersion = root.GetAttribute("version")
ProjectName = root.GetElementsByTagName("name").Item(0).InnerText
But i can't get this values:
VersionCode = VERSION_CODE
MinSdk = MIN_SDK
TargetSdk = TARGET_SDK
FullScreen = FULLSCREEN
Orientation = ORIENTATION
Thank you :)
Upvotes: 1
Views: 1207
Reputation: 5471
As discussed in comments, here is the sample code which you can use to get the values using xpath
Sub test()
Dim objXML, arrNodes, nodesXML, i
Set objXML = CreateObject("MSXML2.DOMDocument.6.0")
With objXML
.SetProperty "SelectionLanguage", "XPath"
.SetProperty "SelectionNamespaces", "xmlns:s='http://www.w3.org/ns/widgets'"
.ValidateOnParse = True
.Async = False
.Load "C:\Users\pankaj.jaju\Desktop\test.xml"
End With
arrNodes = Array("/s:widget/s:preference[@name='android-minSdkVersion']/@value", _
"/s:widget/s:preference[@name='android-versionCode']/@value", _
"/s:widget/s:preference[@name='android-installLocation']/@value", _
"/s:widget/s:preference[@name='android-targetSdkVersion']/@value", _
"/s:widget/s:preference[@name='orientation']/@value", _
"/s:widget/s:preference[@name='fullscreen']/@value", _
"/s:widget/@id", _
"/s:widget/@version", _
"/s:widget/s:name")
For i = LBound(arrNodes) To UBound(arrNodes)
Set nodesXML = objXML.DocumentElement.SelectSingleNode(arrNodes(i))
MsgBox nodesXML.Text
Next
Set nodesXML = Nothing: Set objXML = Nothing
End Sub
Upvotes: 1
Reputation: 125
Ok i found answer :)
Dim doc As XmlDocument = New XmlDocument()
doc.Load("config.xml")
Dim root As XmlElement = doc.DocumentElement
PackageName = root.GetAttribute("id")
ProjectVersion = root.GetAttribute("version")
ProjectName = doc.GetElementsByTagName("name").Item(0).InnerText
For i = 0 To doc.GetElementsByTagName("preference").Count - 1
If (doc.GetElementsByTagName("preference").Item(i).Attributes.Item(0).Value.Contains("fullscreen")) Then
FullScreen = doc.GetElementsByTagName("preference").Item(i).Attributes.Item(1).Value
ElseIf (doc.GetElementsByTagName("preference").Item(i).Attributes.Item(0).Value.Contains("orientation")) Then
Orientation = doc.GetElementsByTagName("preference").Item(i).Attributes.Item(1).Value
ElseIf (doc.GetElementsByTagName("preference").Item(i).Attributes.Item(0).Value.Contains("android-minSdkVersion")) Then
MinSdk = doc.GetElementsByTagName("preference").Item(i).Attributes.Item(1).Value
ElseIf (doc.GetElementsByTagName("preference").Item(i).Attributes.Item(0).Value.Contains("android-targetSdkVersion")) Then
TargetSdk = doc.GetElementsByTagName("preference").Item(i).Attributes.Item(1).Value
ElseIf (doc.GetElementsByTagName("preference").Item(i).Attributes.Item(0).Value.Contains("android-installLocation")) Then
InstallLocation = doc.GetElementsByTagName("preference").Item(i).Attributes.Item(1).Value
ElseIf (doc.GetElementsByTagName("preference").Item(i).Attributes.Item(0).Value.Contains("android-versionCode")) Then
VersionCode = doc.GetElementsByTagName("preference").Item(i).Attributes.Item(1).Value
End If
Next
Upvotes: 0