I'm creating an XNA game. I've made it so I can specify all the level details in an XML file which is then de-serialized and used to set up the level details.
At the moment, it's just referencing a file on my computer - my question is, how do I reference this more generically?
Adding the xml in my content folder created a multitude of complaints about schemas and such like, which made me think that likely wasn't the correct route.
Any suggestions?
I tried removing all the entries from the XNA, this gives:
Attempt to access the method failed: System.IO.StreamReader..ctor(System.String)
EDIT:
The xml:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<XnaContent>
<Asset Type = "RDrop.Level[]">
<Item>
(stuff)
</Item>
<Item>
(stuff)
</Item>
</Asset>
</XnaContent>
EDIT:
I've started a new windows phone project - the previous one wasn't one. I've copied everything over and added "dataTypes" ala this tutorial:
http://msdn.microsoft.com/en-us/library/ff604979.aspx
Game project references -> content, MyDataTypes.
Content references -> MyDataTypes.
The XML is as is in previous edit and is contained in the content folder via Add-> Existing Item-> Level.XML.
Any ideas?
You can leave the build action as "Compile". One method to do what you want is the following:
Create a class that the xml is going to be describing. Example: Level.cs
Then structure your xml file like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<XnaContent>
<Asset Type="The_Level_class_namespace.Level">
<Property1>Value</Property1>
<Property2>Value</Property2>
<Property3>Value</Property3>
<Property4>Value</Property4>
</Asset>
</XnaContent>
if you want the xml to describe an array of objects you can do structure the xml like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<XnaContent>
<Asset Type="The_Level_class_namespace.Level[]">
<Item>
<Property1>Value</Property1>
<Property2>Value</Property2>
<Property3>Value</Property3>
<Property4>Value</Property4>
</Item>
</Asset>
</XnaContent>
From there you just need to make sure your values are in the proper format. For example a vector2 object would be like this:
<Vector2Property>x_value y_value</Vector2Property>
Make sure that your content project references the game project or library project.
Hope this helps :)
Open the properties of your XML document (right click in your content folder). You can set the Build Action to : None.
That way, the compiler won't analyse your schema, thus it won't produce any warnings.
(I'm not entirely sure about this, just my first guess)
Related
So basically I was trying to to add a cover image on my application but unfortunately when trying to build the application it came up with one of the errors I couldn't solve out I was trying to add a cover image with different name however it didn't work out at all. Nota Bene I'm kind of a noob to this sort of problem so sorry, just in case, first time using stackoverflow. I was trying to look up for the answer before.
Code:
<?xml version="1.0" encoding="utf-8" ?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<color android:color="#color/splashBackground"/>
</item>
<item>
<bitmap
android:src="#drawable/Cover"
android:scaleType="matrix"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:tileMode="disabled"
/>
</item>
</layer-list>
Error list output:
*Severity Code Description Project Path File Line Source Suppression State
Error No resource found that matches the given name (at 'src' with value '#drawable/Cover'). Uber Raider C:\Users***\Documents\xamarin\uber\Uber Raider\Uber Raider\Resources\drawable C:\Users***\Documents\xamarin\uber\Uber Raider\Uber Raider\Resources\drawable\splash.xml 2 Build*
I wrote several lines of code but still can't get over this:
I need to load many xml docs from web library. I don't know how many documents there are so I wonder which loop should I use while loading:
XDocument doc = XDocument.Load("http://" + i);
where -i is identifiers number.
I tried loading until i get document without meaningful content (thought it is the end, the rest are empty), but problem is that there is several Xdocs that are empty in the middle of library.
XML with content looks like
<?xml version="1.0" encoding="utf-8"?>
<OP xmlns="" xmlns:xsi="" xsi:schemaLocation="">
<request verb="GR" identifier="53" metadataPrefix="p"></request>
<GR>
<header>
<identifier>53,number of doc...used for counting</identifier>
</header>
<metadata>
<P xmlns="" xsi:schemaLocation="">
<TITLE>title</TITLE>
<CERTIFICATE NAME="different names">
</CERTIFICATE>
<YEAR>
<DATE>2012-10-18T00:00:00Z</DATE>
</YEAR>
<MINIATURE>
<COPY>
<CNAME>Copy name<CNAME>
<FORMAT>obj/max/dxf/3ds/...</FORMAT>
</COPY>
</MINIATURE>
</metadata>
</GR>
</OP>
XML without content
<?xml version="1.0" encoding="utf-8"?>
<OP xmlns="" xmlns:xsi="" xsi:schemaLocation="">
<request verb="GR" identifier="53" metadataPrefix="p"></request>
Furthermore, I need to do some counting like:
Tot.no. of doc,
No. of docs per certificate <CERTIFICATE>
No. of docs for each year <YEAR><DATE>
No of docs for each format <MINIATURE><COPY><FORMAT>
and my output should look like:
<?xml version="1.0" encoding="UTF-8" ?>
<Statistic>
<DocSum>21220</DocSum>
<Certificates>
<Certificate id=”certificateName”>17098</Certificate>
…
<Certificates>
<Years>
<Year year=”2014”>23</Year>
…
</Years>
<Miniature>
<Format post=”obj”>11723</Format>
…
</Miniature>
</Statistic>
If you could give me some help, hints or tips how to deal with it.
The posted answer by smink to the following thread should get you on the right path.
C# HttpWebRequest command to get directory listing
One of the easiest ways to get a list of the files of a web directory without knowing exactly how many there are or their filenames is by parsing the html of the directory and pulling out the tags.
You can then iterate through these tags and filter them out for the files by extensions that you need. I can provide a more in-depth example if necessary.
I currently try updating product data with the Amazon MWS and the Feeds API. My problem: Updating the Inventory and setting a new quantity for my products resolves in errors like this:
The XML you submitted is ill-formed at the Amazon Envelope XML level
at (or near) line X, column Y.
On the other hand, I export nearly the same XML to update the prices. That works just fine...
Here is an example of the XML that i upload to the Feeds API to update the quantity:
<?xml version="1.0" encoding="utf-8"?>
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" noNamespaceSchemaLocation="amznenvelope.xsd">
<Header>
<DocumentVersion>1.01</DocumentVersion>
<MerchantIdentifier>{SellerID}</MerchantIdentifier>
</Header>
<MessageType>Inventory</MessageType>
<Message>
<MessageID>1</MessageID>
<Inventory>
<SKU>ArtNoXX</SKU>
<Quantity>10</Quantity>
</Inventory>
</Message>
<Message>
<MessageID>2</MessageID>
<Inventory>
<SKU>ArtNoXY</SKU>
<Quantity>23</Quantity>
</Inventory>
</Message>
</AmazonEnvelope>
P.S.: I'm using C# and a XMLDocument to create the XML File...
Edit: The Error is shown multiple times. Only the first and the last 3 lines don't appear in the error log.
Example:
... (or near) line 10, column 16.
That would be
<Inventory>
Regarding to the column, it should be
>
Wrong namespace in your config ?
Yours :
noNamespaceSchemaLocation="amznenvelope.xsd"
Should be:
noNamespaceSchemaLocation="amzn-envelope.xsd"
I am having problem to merge 2 or more xml files into 1 using c#.
I am doing it with DataSets:
//ds1,ds2,ds3 are DataSets
private void MyMethod()
{
ds1.ReadXml(tmpStream);
ds2.ReadXml(tmpStream);
ds1.Merge(ds2);
}
but i dont want to use DataSet. i am searching for another way.
first XML is
<?xml version="1.0" encoding="utf-8"?>
<catalog>
<item>
<path>'filePath'</path>
<deleted>0</deleted>
<date>9/23/2010 11:30:03 AM</date>
</item>
</catalog>
the second is
<?xml version="1.0" encoding="utf-8"?>
<catalog>
<item>
<path>'filePath'</path>
<deleted>0</deleted>
<date>9/23/2010 11:30:03 AM</date>
</item>
</catalog>
result must be
<?xml version="1.0" encoding="utf-8"?>
<catalog>
<item>
<path>'filePath'</path>
<deleted>0</deleted>
<date>9/23/2010 11:30:03 AM</date>
</item>
<item>
<path>'filePath'</path>
<deleted>0</deleted>
<date>9/23/2010 11:30:03 AM</date>
</item>
</catalog>
Though this isn't really clear of what sort of merge you want, this article Merging XML Files, Schema Validation, and More might help you get the idea.
Easiest could be, if you dont want any checks to be performed(duplicates, zombies, etc)
var ResultXml = XDocument.Load("file1.xml");
ResultXml.Root.Add(XDocument.Load("file2.xml").Root.Elements());
To merge XML files into resulting one, you could use Microsoft's XML Diff and Patch C# API. You could read more about it in Eric White's blog post: "OpenXmlDiff.Exe: A Utility to Find the Differences Between Two Open XML Documents"
I am having problem loading the testdata.xml into ndbunit,
I followed http://code.google.com/p/ndbunit/wiki/QuickStartGuide,
but the test data is not loaded when I run my unit test in NUnit.
Is there any gotcha that I am not aware of ?
I had the same problem. Then I noticed that my xml file did not have the namespace in it
i.e.
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
instead of
<?xml version="1.0" standalone="yes"?>
<NewDataSet
xmlns="http://tempuri.org/Database.xsd" >
Once I put the namespace in, my tests were happy again.