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.
Related
I have an XML as below
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope
xmlns="http://com/uhg/uht/uhtSoapMsg_V1"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header>
<uhtHeader
xmlns="http://com/uhg/uht/uhtHeader_V1">
<consumer>COMET</consumer>
<auditId></auditId>
<sendTimestamp>2020-09-03T18:15:40.942-05:00</sendTimestamp>
<environment>P</environment>
<businessService version="24">getClaimHistory</businessService>
<status>success</status>
</uhtHeader>
</env:Header>
<env:Body>
<srvcRspn
xmlns="http://com/uhg/uht/getClaimHistory_V24">
<srvcErrList arrayType="srvcErrOccur[1]" type="Array">
<srvcErrOccur>
<orig>Foundation</orig>
<rtnCd>00</rtnCd>
<explCd>000</explCd>
<desc></desc>
</srvcErrOccur>
</SrvcErrList>
</srvcRspn>
</env:Body>
</env:Envelope>
I want to remove all the attribute values with "http" like below:
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope
xmlns=""
xmlns:env="">
<env:Header>
<uhtHeader
xmlns="">
<consumer>COMET</consumer>
<auditId></auditId>
<sendTimestamp>2020-09-03T18:15:40.942-05:00</sendTimestamp>
<environment>P</environment>
<businessService version="24">getClaimHistory</businessService>
<status>success</status>
</uhtHeader>
</env:Header>
<env:Body>
<srvcRspn
xmlns="">
<srvcErrList arrayType="srvcErrOccur[1]" type="Array">
<srvcErrOccur>
<orig>Foundation</orig>
<rtnCd>00</rtnCd>
<explCd>000</explCd>
<desc></desc>
</srvcErrOccur>
</SrvcErrList>
</srvcRspn>
</env:Body>
</env:Envelope>
I have tried several ways but none of them has worked for me. Can anyone suggest what is fastest way to do it in VB.NET/C#.
The actual response is very large (approx 100000 lines of XML minimum) and using for each will consume a good amount of time. Is there any parsing method or LINQ query method which can do it faster.
I got the way to do it using Regex as below:
Return Regex.Replace(xmlDoc, "((?<=<|<\/)|(?<= ))[A-Za-z0-9]+:| xmlns(:[A-Za-z0-9]+)?="".*?""", "")
It serves my purpose completely. Thanks Cleptus for your quick reference.
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 want to know how to remove :
<?xml version="1.0" encoding="UTF-8"?>
from a string data.
I have tried this but it doesn't work
string result = data.Replace("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>", "");
(I am not working with xml , it's just a response to manipulate it without header )
Let's look at your two strings. Removing the escapes they are:
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8" ?>
In other words you've managed to add an extra space. Remove that and your code will succeed.
More broadly, one wonders why you are attempting to do this. Simple text processing of XML files is liable to lead to pain and suffering. Perhaps you should consider using a parser.
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)
I have a XML template file like so
<?xml version="1.0" encoding="us-ascii"?>
<AutomatedDispenseResponse>
<header shipmentNumber=""></header>
<items></items>
</AutomatedDispenseResponse>
When I use XDocument.Load, for some reason the
<?xml version="1.0" encoding="us-ascii"?>
is dropped.
How do I load the file into a XDocument and not losing the declaration at the top?
I suspect it's not really dropping the declaration on load - it's when you're writing the document out that you're missing it. Here's a sample app which works for me:
using System;
using System.Xml.Linq;
class Test
{
static void Main()
{
XDocument doc = XDocument.Load("test.xml");
Console.WriteLine(doc.Declaration);
}
}
And test.xml:
<?xml version="1.0" encoding="us-ascii" ?>
<Foo>
<Bar />
</Foo>
Output:
<?xml version="1.0" encoding="us-ascii"?>
The declaration isn't shown by XDocument.ToString(), and may be replaced when you use XDocument.Save because you may be using something like a TextWriter which already knows which encoding it's using. If you save to a stream or just to a filename, it's preserved in my experience.
It is loaded. You can see it and access parts of it using:
XDocument.Parse(myDocument).Declaration