logo

Live Production Software Forums


Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
MattGrover  
#1 Posted : Tuesday, March 21, 2023 9:58:38 PM(UTC)
MattGrover

Rank: Member

Groups: Registered
Joined: 7/20/2020(UTC)
Posts: 14
Man
United Kingdom
Location: Henfield

Hi All,

I'm working on a new bit of script in which I'm pulling from the API XML for the first time, I'm getting the error Error Line 9: Object reference not set to an instance of an object.

My guess at the moment is I'm not understanding the syntax for pulling info out of a XML path/line/appropriate term.
At this stage I'm trying to pull the current selectedIndex of a List Input to then use in the rest of the script. Any guidance as to what I'm doing wrong is much appreciated.
Thanks!

Code:
'Grab Selected Index Test

'load vMix API xml in to memory
dim xml as string = API.XML()
dim x as new system.xml.xmldocument
x.loadxml(xml)

'check slide number and display
    dim CurrentSlide as String = (x.SelectSingleNode("//input[@title='holding']//selectedIndex").InnerText)
    console.writeline(CurrentSlide)
doggy  
#2 Posted : Tuesday, March 21, 2023 11:20:55 PM(UTC)
doggy

Rank: Advanced Member

Groups: Registered
Joined: 12/27/2012(UTC)
Posts: 5,075
Belgium
Location: Belgium

Thanks: 284 times
Was thanked: 920 time(s) in 759 post(s)
The xpath is not refering to an existing node
dmwkr  
#3 Posted : Tuesday, March 21, 2023 11:29:47 PM(UTC)
dmwkr

Rank: Advanced Member

Groups: Registered
Joined: 2/23/2019(UTC)
Posts: 512

Thanks: 62 times
Was thanked: 119 time(s) in 108 post(s)
Look for the difference between Elements and Attributes:
https://www.w3schools.com/xml/xml_attributes.asp

And look how their contents are referenced as "InnerText" and "Value":
https://forums.vmix.com/...86-Scripting-for-Dummies
doggy  
#4 Posted : Tuesday, March 21, 2023 11:33:25 PM(UTC)
doggy

Rank: Advanced Member

Groups: Registered
Joined: 12/27/2012(UTC)
Posts: 5,075
Belgium
Location: Belgium

Thanks: 284 times
Was thanked: 920 time(s) in 759 post(s)
try (x.SelectSingleNode("//input[@title='holding']/@selectedIndex").Value)

But do what DMWKR said for future reference
MattGrover  
#5 Posted : Wednesday, March 22, 2023 1:03:08 AM(UTC)
MattGrover

Rank: Member

Groups: Registered
Joined: 7/20/2020(UTC)
Posts: 14
Man
United Kingdom
Location: Henfield

Quote:

The xpath is not refering to an existing node


Yes, I'm presuming my xpath is incorrect..

Quote:
try (x.SelectSingleNode("//input[@title='holding']/@selectedIndex").Value)

But do what DMWKR said for future reference


This gave the same error. Error Line 9: Object reference not set to an instance of an object.

I looked at the links DMWKR posted (thanks) and I'm already using the Scripting for Dummies examples (and others) as a reference, but what I don't understand at the moment it seems is the structure of the xpath in this instance.

the xml line I'm working with is

Code:
<input key="e285d586-c76c-493f-90ed-1c34d2f6ce83" number="23" type="VideoList" title="holding - Socials.png" shortTitle="holding" state="Running" position="0" duration="0" loop="False" muted="True" volume="100" balance="0" solo="False" audiobusses="" meterF1="0" meterF2="0" gainDb="0" selectedIndex="1">
dmwkr  
#6 Posted : Wednesday, March 22, 2023 1:19:19 AM(UTC)
dmwkr

Rank: Advanced Member

Groups: Registered
Joined: 2/23/2019(UTC)
Posts: 512

Thanks: 62 times
Was thanked: 119 time(s) in 108 post(s)
Originally Posted by: MattGrover Go to Quoted Post

Code:
<input key="e285d586-c76c-493f-90ed-1c34d2f6ce83" number="23" type="VideoList" title="holding - Socials.png" shortTitle="holding" state="Running" position="0" duration="0" loop="False" muted="True" volume="100" balance="0" solo="False" audiobusses="" meterF1="0" meterF2="0" gainDb="0" selectedIndex="1">


You are using "holding" as title. But the "title" is "holding - Socials.png", "shortTitle" would be "holding".
MattGrover  
#7 Posted : Wednesday, March 22, 2023 1:27:58 AM(UTC)
MattGrover

Rank: Member

Groups: Registered
Joined: 7/20/2020(UTC)
Posts: 14
Man
United Kingdom
Location: Henfield

Goddammit I'm an idiot!

Thank you!

So looks like a combo of using the wrong title reference (hence why it didn't exist) and ALSO my formatting of "//selectedIndex" which didn't work, but changing it to "/@selectedIndex" as Doggy suggested makes the line work now. I'll do more research to understand the why

Thanks to both of you!
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.