Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by magicbananna · Jan 05, 2019 at 06:02 AM · xmlxmlserializer

unity and xml question

Ok firstly let me break down what I am trying to achieve.

Im using a photon2 setup where the room is created and run in a headless mode so It basically starts the lobby and room with no players. other players can then join from a list of all availiable rooms.

Because im running a headless version I would like the person who starts the (Server/lobby/room) to be able to make a custom name and info for the room that the other players will find in the list.

This works in the normal build by the owner declaring the name and stuff from unities UI. But because I will ship a headless version I would like all the options inc. name, to be sorted out from an xml doc.

This is the basic xml setup.

 <?xml version="1.0" encoding="utf-8"?>
  <ServerSettings>
    <Settings>
      <serverName>test server of doom</serverName>
      <Max_Players>100</Max_Players>
      <Game_Mode>pvp/pve</Game_Mode>
    </Settings>
  </ServerSettings>

Now because this will be defined by the player I have the .xml in the StreamingAssets folder. I have done this so the person with the headless build can find the file to change it. And this is where I am coming unstuck.

I need to know how to get the data from the xml from streaming assets and convert it to the roomName variable.

This is what I have but im getting stuck... any help and I will love you forever:

 public void GetserverDetails(string xmlData)
      {
    
          XmlDocument mlcDoc = new XmlDocument();
          mlcDoc.Load(new StringReader(xmlData));
          string pathPatthern = Application.dataPath + "/StreamingAssets/serversettings.xml";
          XmlNodeList xmlnode = mlcDoc.SelectNodes(pathPatthern);
          foreach(XmlNode node in xmlnode)
          {
              XmlNode serverName = node.FirstChild;
              roomName = serverName.ToString();
          }
          
      }

current code gives this error:

 XmlException: Document element did not appear.  Line 1, position 1.
 Mono.Xml2.XmlTextReader.Read ()
 System.Xml.XmlTextReader.Read ()
 Mono.Xml.EntityResolvingXmlReader.Read ()
 Mono.Xml.DTDValidatingReader.ReadContent ()


Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by magicbananna · Jan 06, 2019 at 09:15 AM

So I finally figgured it out so If anyone in the future needs this:

 void Start () {
         string data = Application.dataPath + "//StreamingAssets/serversettings.xml";
         
         
         PhotonNetwork.GameVersion = _gameVersion;
         PhotonNetwork.ConnectUsingSettings();
         Debug.Log("called");
         GetserverDetails(data);
 
     }
 
     private void Awake()
     {
         instance = this;
     }
 
     public void GetserverDetails(string xmlData)
     {
   
         XmlDocument mlcDoc = new XmlDocument();
         mlcDoc.Load(xmlData);
         string pathPatthern = "//ServerSettings";
         XmlNodeList xmlnode = mlcDoc.SelectNodes(pathPatthern);
         foreach(XmlNode node in xmlnode)
         {
             XmlNode serverName = node.FirstChild;
             roomName = serverName.InnerXml.ToString();
         }
         
     }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

96 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Confusion with process of XML setup 0 Answers

Parse XML to Vector3 (and other objects you don't control) 0 Answers

Problems with the XML Serializer 1 Answer

Need Help With XML Reading Class Initialization 1 Answer

I dont understand why the script to read .xml doesnt works. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges