I have problem with properly using XPathSelectElement
. I'm trying to find element in XML file by XPathSelectElement.
this.xdocument = XDocument.Parse (this.loadDialogues ());
XElement element = this.xdocument.XPathSelectElement ("/dialogues/npc[@npcid='1']/conversation[@id='1']/message[@mid='1']/options/option[@oid='1']/text()");
It is giving me this error:
NullReferenceException: Object reference not set to an instance of an object
But when I run for ex. this query:
XElement element = this.xdocument.XPathSelectElement ("/dialogues/npc");
Everything is ok. Can anyone tell me what is wrong? I can't find anything about this error in that context.
My XML example file:
<dialogues>
<!-- Greetings messages -->
<greetings>
<friendly>
<text id="1">Witaj przybyszu! W czym mogę Ci pomóc?</text>
<text id="2">Aniele, co Cię do mnie sprowadza?</text>
<text id="3">Witaj przybyszu! Czy szukasz czegoś konkretnego?</text>
</friendly>
<agressive>
<text id="1">Czego chcesz? Nie mam ochoty rozmawiać więc się streszczaj.</text>
<text id="2">Możesz mnie zostawić? To wszystko mnie przerasta...</text>
</agressive>
</greetings>
<!-- Farewells -->
<farewells>
<friendly>
<text id="1">Żegnaj</text>
<text id="2">Dziękuję, żegnaj</text>
<text id="3">Do zobaczenia</text>
</friendly>
<agressive>
<text id="1">***** z moich oczu, przybłędo</text>
<text id="2">Odejdź stąd natychmiast, nie masz tu czego szukać</text>
</agressive>
</farewells>
<!-- Monologs -->
<monologs>
<monolog id="1">
<text id="1">
Monolog się rozpoczyna...
</text>
<text id="2">
Monolog, część środkowa...
</text>
<text id="3">
Monolog się kończy...
</text>
</monolog>
</monologs>
<!-- NPC -->
<npc npcid="1">
<conversation id="1">
<message mid="1" trigger="greetingRandom(friendly)">
<options>
<option oid="1" nextmid="2">Tak, możesz mi powiedzieć gdzie znajdę Kaplicę?</option>
<option trigger="endConversationRandom(friendly)"></option>
</options>
</message>
<message mid="2">
<text>Musisz pójść prosto, u dołu tych schodów będzie strażnik. Powiedz mu, żę Cię przysyłam, wtedy nie powinien robić problemów.</text>
<options>
<option oid="1" trigger="endConversation">Dziękuję, żegnaj.</option>
</options>
</message>
</conversation>
</npc>
//EDIT: Full error with more info
NullReferenceException: Object reference not set to an instance of an object
System.Xml.Linq.XNodeNavigator.get_NodeType ()
System.Xml.XPath.NodeTypeTest.Match (IXmlNamespaceResolver nsm, System.Xml.XPath.XPathNavigator nav)
System.Xml.XPath.AxisIterator.MoveNextCore ()
System.Xml.XPath.BaseIterator.MoveNext ()
System.Xml.XPath.SimpleSlashIterator.MoveNextCore ()
System.Xml.XPath.BaseIterator.MoveNext ()
System.Xml.XPath.SlashIterator.MoveNextCore ()
System.Xml.XPath.BaseIterator.MoveNext ()
System.Xml.XPath.SortedIterator..ctor (System.Xml.XPath.BaseIterator iter)
System.Xml.XPath.ExprSLASH2.Evaluate (System.Xml.XPath.BaseIterator iter)
System.Xml.XPath.Expression.EvaluateNodeSet (System.Xml.XPath.BaseIterator iter)
System.Xml.XPath.CompiledExpression.EvaluateNodeSet (System.Xml.XPath.BaseIterator iter)
System.Xml.XPath.XPathNavigator.Select (System.Xml.XPath.XPathExpression expr, IXmlNamespaceResolver ctx)
System.Xml.XPath.XPathNavigator.Select (System.Xml.XPath.XPathExpression expr)
System.Xml.XPath.XPathNavigator.SelectSingleNode (System.Xml.XPath.XPathExpression expression)
System.Xml.XPath.XPathNavigator.SelectSingleNode (System.String xpath, IXmlNamespaceResolver nsResolver)
System.Xml.XPath.Extensions.XPathSelectElement (System.Xml.Linq.XNode node, System.String xpath, IXmlNamespaceResolver nsResolver)
System.Xml.XPath.Extensions.XPathSelectElement (System.Xml.Linq.XNode node, System.String xpath)
DialogueParser.getConversation (Int32 npcID, Int32 conversationID) (at Assets/Dedicated Assets/Scripts/Dialogue/DialogueParser.cs:38)
DialogueManager.Awake () (at Assets/Dedicated Assets/Scripts/Dialogue/DialogueManager.cs:33)