Search Unity

Build Error Windows Store Universal App 10 using XmlDocument

Discussion in 'Windows' started by Grisu1004, Sep 26, 2015.

  1. Grisu1004

    Grisu1004

    Joined:
    Aug 25, 2015
    Posts:
    7
    I am using 5.2.1p1 (64 bit) and I tried to build a Windows 10 Universal Project.
    The following line of code causes an error:

    XmlDocument mResourceDictionary;

    string result = mResourceDictionary.SelectSingleNode("//Resources/String[@ID='" + ID + "']").InnerText;

    The error states

    'System.Xml.XmlDocument' contains no definition for 'SelectNodes' and no extension method 'SelectNodes' could be found.

    This also happened when building an Universal App for 8.1.
    This also happened when trying to use SelectSingleNode.

    The code compiles fine in VS 2015 and building standalone (for Windows) and Android worked!
     
  2. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    1,989
  3. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,513
  4. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    1,989
    It's low priority... so I wouldn't want to raise your hopes...
     
  5. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,513
    Rats. That's the last thing I need to port my code too. I use these methods everywhere and re-writing it all in a different manner is a major PITA. That source you pointed to is great but mostly won't work as it relies on all sorts of other not available stuff.
     
  6. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,513
    So for anyone else coming this way and unfamiliar with XDocument. What I found out so far is that it's easier to replace XmlDocument with XDocument and then use Element and Elements (as well as potentially Descendants) to replace SelectSingleNode and SelectNodes

    So something like:
    Code (CSharp):
    1. XDocument xdoc = XDocument.Parse(xmlText);
    2. var singleNode = xdoc.Element("exampleNode");
    3. var listOfNodes = singleNode.Elements("exampleNodes");
    4.  
    5. foreach (XElement e in listOfNodes)
    6. {
    7.      string exampleAttr = e.Attribute("code").Value;
    8.      string exampleInnerText = e.Value;
    9. }
     
  7. andyblem

    andyblem

    Joined:
    Nov 11, 2014
    Posts:
    20
    Instead of using SelectNodes use GetElementByTagName.
    Try something like this.

    Code (CSharp):
    1. XmlDocument xmlDoc = XmlDocument();
    2.  
    3. xmlDoc.LoadXml(yourTextFile);
    4.  
    5. XmlNodeList xnList = xmlDoc.GetElementByTag(childTagName);
     
  8. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,513
    Have they added support for XmlDocument to Universal App builds?
     
  9. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    1,989
    Yes, Microsoft brought back XmlDocument to Universal App builds, but I think some pieces are still missing:
    • System.Xml.Schema.* stuff
    • System.Xml.Formatting
    • System.Xml.XmlEntity
    • System.Xml.XmlEntityReference
    • System.Xml.XmlNodeReader
    • System.Xml.XmlNotation
    • System.Xml.XmlOutputMethod
    • System.Xml.XmlResolver
    • System.Xml.XmlTextReader
    • System.Xml.XmlTextWriter
    • System.Xml.XmlTokenizedType
    • System.Xml.XmlUrlResolver
    • System.Xml.XmlValidatingReader
     
  10. hypnoslave

    hypnoslave

    Joined:
    Sep 8, 2009
    Posts:
    282
    What a delightful thing to discover! bad news for us.

    Tomas (or anyone else) are you aware of a decent replacement for SelectSingleNode that actually IS supported? I'm needing to parse a third-party generated XML document, and I've got to select nodes deep inside a tree that can only be cleanly identified by children that have children that have unique data stashed inside them.

    For example, I've been using:
    root.SelectSingleNode("Assets/Conversations/Conversation[Fields/Field[Value='"+conversationName+"']]")
    to grab an XMLElement.

    I know that I could use GetElementsByTag to get a list, and then iterate through the list, each time iterating through a list of children, until I find the right identifier, but I might kill myself long before attempting that.
     
  11. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    2,279
    Have you tried using XDocument?
     
  12. hypnoslave

    hypnoslave

    Joined:
    Sep 8, 2009
    Posts:
    282
    Well... er... no. Despite monark's post, after a little Googling I got the impression that it wasn't supported, for some reason.

    I take from your question that I made a mistake there.. heh. I'll go back and implement that now, and see what happens.

    Thanks Aurimas! The response is very much appreciated.
     
  13. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,513
    XDocument is supported, I went to quite a lot of trouble to have some classes that hide the translation between XDocument and XmlDocument (don't confuse the 2) for cross platform compiling.
    If they have brought back support for XmlDocument that would mostly make that redundant now :(
    But if you don't need to be cross platform XDocument is fine and dandy.
     
  14. OFFIS_sebastian

    OFFIS_sebastian

    Joined:
    Sep 11, 2017
    Posts:
    2
    Has anyone solved this by now? I'm having trouble using the Graph and Chart Engine by prosourcelabs due to that exact reason...