Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XPath Namespace Issue

Status
Not open for further replies.

EBGreen

Programmer
Apr 1, 2004
2,867
US
I've researched this on my own and haven't been able to resolve it. I have an XML like this:
Code:
  <?xml version="1.0" encoding="utf-8" ?> 
<PrimaryRoles xmlns="[URL unfurl="true"]http://blah/PrimaryRole.xsd">[/URL]
  <PrimaryRole pRoleID="1" name="MSG Base Build">
    <SecondaryRoles>
      <SecondaryRole sRoleID="123" name=".NET Developer">
      <Description>This role installs software for a .NET Developer</Description> 
      <Bundles>
        <Bundle bundleID="1232">
        <SMSInstallPath>\MS\Visio\XP\setup.exe</SMSInstallPath> 
          <CommandLine>--checkdep=true</CommandLine> 
        </Bundle>
        <Bundle bundleID="1235">
          <SMSInstallPath>\MS\Project\XP\setup.exe</SMSInstallPath> 
          <CommandLine /> 
        </Bundle>
      </Bundles>
      </SecondaryRole>
    </SecondaryRoles>  
  </PrimaryRole>
</PrimaryRoles>

I have an XSD like this:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="PrimaryRole" targetNamespace="[URL unfurl="true"]http://foo.com/schemas/PrimaryRole.xsd"[/URL]
	elementFormDefault="qualified" xmlns="[URL unfurl="true"]http://foo.com/schemas/PrimaryRole.xsd"[/URL]
	xmlns:mstns="[URL unfurl="true"]http://foo.com/schemas/PrimaryRole.xsd"[/URL] xmlns:xs="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema">[/URL]
	<xs:element name="PrimaryRoles" type="PrimaryRoles"></xs:element>
	<xs:complexType name="PrimaryRoles">
		<xs:complexContent>
			<xs:restriction base="xs:anyType">
				<xs:sequence>
					<xs:element name="PrimaryRole" type="PrimaryRole" minOccurs="0" maxOccurs="unbounded" />
				</xs:sequence>
			</xs:restriction>
		</xs:complexContent>
	</xs:complexType>
	<xs:complexType name="PrimaryRole">
		<xs:complexContent>
			<xs:restriction base="xs:anyType">
				<xs:sequence>
					<xs:element name="SecondaryRoles" type="SecondaryRoles" minOccurs="1" maxOccurs="1" />
					<xs:element name="Bundles" type="Bundles" minOccurs="1" maxOccurs="1" />
				</xs:sequence>
				<xs:attribute name="pRoleID" type="xs:positiveInteger" use="required" />
				<xs:attribute name="name" type="xs:string" use="required" />
			</xs:restriction>
		</xs:complexContent>
	</xs:complexType>
	<xs:complexType name="SecondaryRoles">
		<xs:complexContent>
			<xs:restriction base="xs:anyType">
				<xs:sequence>
					<xs:element name="SecondaryRole" type="SecondaryRole" minOccurs="0" maxOccurs="unbounded" />
				</xs:sequence>
			</xs:restriction>
		</xs:complexContent>
	</xs:complexType>
	<xs:complexType name="SecondaryRole">
		<xs:complexContent>
			<xs:restriction base="xs:anyType">
				<xs:sequence>
					<xs:element name="Description" type="xs:string" minOccurs="1" maxOccurs="1" />
					<xs:element name="Bundles" type="Bundles" maxOccurs="1" minOccurs="1" />
				</xs:sequence>
				<xs:attribute name="sRoleID" type="xs:positiveInteger" use="required" />
				<xs:attribute name="name" type="xs:string" use="required" />
			</xs:restriction>
		</xs:complexContent>
	</xs:complexType>
	<xs:complexType name="Bundles">
		<xs:complexContent>
			<xs:restriction base="xs:anyType">
				<xs:sequence>
					<xs:element name="Bundle" minOccurs="0" type="Bundle" maxOccurs="unbounded" />
				</xs:sequence>
			</xs:restriction>
		</xs:complexContent>
	</xs:complexType>
	<xs:complexType name="Bundle">
		<xs:complexContent>
			<xs:restriction base="xs:anyType">
				<xs:sequence>
					<xs:element name="SMSInstallPath" type="xs:string" minOccurs="1" maxOccurs="1" />
					<xs:element name="CommandLine" type="xs:string" minOccurs="1" maxOccurs="1" />
				</xs:sequence>
				<xs:attribute name="bundleID" type="xs:positiveInteger" />
			</xs:restriction>
		</xs:complexContent>
	</xs:complexType>
</xs:schema>
Iam trying to use this code in VBScript to get info:
Code:
Option Explicit

Dim xml
Dim xpath
Dim buf
Dim bContinue
Dim node
Dim oCol
Dim oName

set xml = CreateObject("MSXML2.DOMDocument")
xml.async = false
xml.setProperty "SelectionLanguage", "XPath"
xml.load("PrimaryRoleSample.xml")
 
set xpath = xml.selectNodes("/PrimaryRoles/*")
xpath.context = xml

buf = ""
bContinue = True
while (bContinue)
    Set node = Nothing
    Set node = xpath.nextNode()
    if Not (node Is Nothing) then 
       'WScript.Echo node.Text
       buf = buf & node.NodeName & vbCrLf
    else
      bContinue = False
   end if
Wend
WScript.Echo buf

I am not getting any returned nodes. I know that my problem has to do with the default namespace and not being able to reference it directly, but I haven't been able to figure out how to correct it.

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
Never mind. I found the answer. I needed to use setProperty to add a namespace to the SelectionNamespaces property. I can post the code if anyone needs it.

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top