|
whats the exception?
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
Hi
This probably doesn´t help but when I used
lstElement->Item(0)->NamespaceURI in creating an xmlElemnt
XmlElement *NameElement = doc->CreateElement("Name",lstElement->Item(0)->NamespaceURI);
given that doc is an XMLDocument and lstElement is of type XmlNodelist. I got it to work.
But again, I assume that there are two different problems. I added elements to an existing XMLDocument.
Regards
Daniel
|
|
|
|
|
Hi !
I have a problem with serializing a class, which has a variable with an abstract-class-type.
If I'm using the specific class Test2, everything works fine,
but when I use the abstract class Test, I get the following error-message:
An unhandled exception of type 'System.InvalidOperationException' occurred in system.xml.dll
Additional information: There was an error generating the XML document.
Does anybody know whats the matter here?
using System;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
namespace xmlTest
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
myObject o = new myObject();
XmlSerializer mySerializer = new XmlSerializer(typeof(myObject));
StreamWriter myWriter = new StreamWriter("test.xml");
mySerializer.Serialize(myWriter, o);
}
}
public class myObject
{
//public Test2 t = new Test2();
public Test t = new Test2();
}
public abstract class Test
{
public string s = "Test";
}
public class Test2:Test
{
new public string s="Test2";
}
}
Thank you !!!!
|
|
|
|
|
As the documentation states, serializable classes must have a publicly accessible default constructor because they are instantiated. Abstract classes cannot be instantiated, however. That is the problem.
The solution is easy: don't hardcode the type (using typeof in your example) in your serializable code. For one, one of the benefits (one could say, the "point") of using abstract classes is that you can use a generic to refer to multiple types without caring about the specific Type of the object. Instead, use o.GetType() .
Remember that in OO, even though a variable might be declared as Test or Object (pulling examples from your code), they will still be instances of myObject or Test2 . So, using o.GetType() will still return the Type for myObject (even if it were declared as an Object ).
If you use that in the constructor for the XmlSerializer , you shouldn't have any problems. This way, also, you don't hardcode that the serializer only accepts myObject . You will want to, however, use a condition or something before serializing to make sure that the object to be serialized is a Test derivative:
public void SaveTest(Test t)
{
XmlSerializer serializer = new XmlSerializer(t.GetType());
StreamWriter writer = new StreamWriter("test.xml");
serializer.Serialize(writer, t);
}
public void Save(object o)
{
if (o is Test)
SaveTest(o as Test);
}
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I started using SaveFileDialog in my application.
But the problem is that once I save anything to a directory different than the one that
the application is stored in, an error appears because the application can't get files in this way:
XmlTextReader reader = new XmlTextReader("loc.xml");
schemaColl.Add(null, "XMLSchema.xsd");
I can't store the absut path in my application (like that: schemaColl.Add(null, "d:\MyApp\\\XMLSchema.xsd");
Is there any simple method how to solve this problem?
Many thanks for help in advance.
misiek
-------------------------------------------------------------
My problem has been solved.
The solutions is here
|
|
|
|
|
I'm transforming xml and want to strip out null characters in the elements.
The elements look like this:
<myEl>���</myEl>
My XSL rules look like this:
<xsl:if test="string-length(/myEl) > 0">
<outEl><xsl:value-of select="/myEl"/></outEl>
</xsl:if>
For the 'select=' attribute, I've tried:
- translate(/myEl, �, 'x')
- translate(/myEl, '�', 'x')
- translate(/myEl, '�', 'x')
- translate(/myEl, '�', 'x')
- translate(/myEl, '�', 'x')
- translate(string(/myEl), '�', 'x')
- translate(string(/myEl), '�', 'x')
I've also tried <xsl:strip-space> at the root, but no effect.
I'm translating null to 'x' for now so I know that I'm capturing the nulls correctly, but never get a match; my output always has <myEl> with nulls embedded in it. The output xml is otherwise well-formed.
Anyone know what I'm doing wrong?
|
|
|
|
|
I solved the problem, which had nothing to do with the XPath queries. My XSL stylesheet is a Content file in a VS.NET project. I forgot that VS DOESN'T copy content files to the output folder. Thus, all of my stylesheet edits were never used!
This is what I ultimately used to remove the nulls:
translate(/myEl, '�', '')
Does anyone know why VS doesn't copy content files to output folder?
|
|
|
|
|
In the app i am currently building, I need to display, and print, reports of data records (tables, images, etc). I want to offload the formatting work to someone else, and am currently attempting to give this reponsibility to the WebBrowser activeX control.
I pump out an XML file of the report, and have an XSLT file to format this to html. However, as pretty as this looks in the webbrowser control, it does not print well, as html is continuous.
I have looked into XSL-FO, but this seems too complex for my task. I would like to use print templates in IE, however when i attempt to work with print templates in an xsl file I encounter parsing errors. Any ideas?
|
|
|
|
|
you need to use CDATA to stop xslt trying to parse the print templates..
<![CDATA[<br />
stuff that is not xml (in your case print templates)<br />
]]>
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
Hi
i seem to be getting an intermitant error
in my application when i send XML posts to our
web service
the error is
Run-time error '-2146697211 (800c0005)'
does ne1 have any ideas ? it only seems to happen
ocassionally
thnkas
si
|
|
|
|
|
I am trying to figure out if the following is even possible:
XML file is as follows:
<section1>
<section2 attribA="123">
<param ref="paramX">456</param>
<param ref="paramY">789</param>
</section2>
</section1>
Windows Form App contains a pulldown and a datagrid.
The pulldown contains the all the "attribA" values in "section2" of the XML file,
and the datagrid is 2 columns, containg the "param" elements (displays "paramX | 456" in the 2 columns) for the selected element in "section2".
Can this be done with datasets & data binding? Or must I reparse the entire XmlDoc with every change event on the pulldown?
I haven't had much luck at it so far..
~Mike Stanbrook
|
|
|
|
|
Granted I am much the novice, when it comes to programming, but in my search for a QUALITY book that really allows someone to learn XML, one step at a time, appears NOT to exist!
I have reviewed just about all the books out there, and am a bit surprised that none of them really TEACH xml. Many discuss this and that, but none really set up the foundation and build from there.
If anyone has 'other' information or can give me some ISBN #'s that may be more in-line with my need, I'd SURE appreciate the info.
My primary focus with XML is implementing into ASP.NET at work. Unfortunately for me, my employer does not like to spend money on formal classroom training, so anything I need to learn, I must do by Self-Study.
For those who've been posting articles on "The Code Project", all I can say is THANKS! Without many of the ASP.NET and C# articles, I would be totally bald (Crew cut now).
Regards.
KoalaCowboy
Knowledge Monger
|
|
|
|
|
try the Beginning XML by WROX
Actually I like all WROX books.
www.wrox.com
you should be able to find all of them at amazon..
theJazzyBrain
Wise is he who asks good questions, not he who gives good answers
|
|
|
|
|
I second that!
Excellent book.
Author is David Hunter.
~Mike Stanbrook
|
|
|
|
|
I am creating my first web service using .net. Will clients using perl lite to access my service run into any problems? Is there anything I need to do to make the web service more friendly to non Microsoft users?
Jason W.
|
|
|
|
|
Jason Weibel wrote:
non Microsoft users?
They exist? Ok, just joking. I assume you are talking about this[^]? If so, it looks like it supports both the SOAP 1.1 and 1.2 specs so you should be ok. Have you tried to create a quick example using it, there are plenty of examples listed.
-Nick Parker
|
|
|
|
|
I’m fairly new to the web service world so try not to laugh if this is a dumb question. Using visual studio .net I have created a web service and a client side app to make requests to that service. The current requests are simply passing string variables. If possible I would like to pass the entire contents of an xml document, how is this done?
Thanks
Jason W.
|
|
|
|
|
here is a simple example:
[WebMethod(
Description = "a test of passing XML documents"
)]
public XmlDocument AddElementToDocument(XmlDocument source, string elementName)
{
source.ChildNodes[0].AppendChild(source.createElement(elementName));
return source;
}
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
|
Ok, I have setup the web service as such, basically the VB equivalent of your code:
<br />
<WebMethod()> _<br />
Public Function AddElementToDocument(ByVal source As XmlDocument) As String<br />
Return "Accepted"<br />
End Function<br />
Now I can’t get the client app to pass the document to the service. The function is asking for a system.xml.xmlnode object. Why is it prompting for that and what needs to be done about it? Thanks your help.
Jason W.
|
|
|
|
|
whats the client code....
also "ByVal" - should be ByRef?
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
|
Hi All,
Can anyone recommend a good book for XML Web Services.
I have been tasked with learning more about this but not sure what book to start with.
Thanks In Advance
Tony
|
|
|
|
|
I have ‘Real World XML Web Services By Yasser Shohoud’ and have gotten a lot out of it. This book is aimed at VB and VB.Net programmer if you don’t fall into that category I would try something else. My one complaint about the book is the examples do not get complex enough. There are some sample chapters and articles by Yasser at http://www.learnxmlws.com/learn/tutors.aspx.
A second book I have is ‘Applied XML Programming for Microsoft .NET by Dino Esposito‘ it is a very good in-depth book about XML programming, it doesn’t touch web services as deeply as Yasser’s book but it has a lot of good stuff in it. All the code in the book is written in C#.
In learning how to program web services I still have had question that I wasn’t able to answer with the books but I think you will have that with ever thing. Both these books are aimed at .net web services so keep that in mind when considering them.
Note, just because I think these are good books doesn’t mean you will agree. I say that because Yasser’s book had several good reviews on amazon and one horrible one. Basically it comes down to were the books worth the $30 I paid for each of them, yes.
Jason W.
|
|
|
|
|
Hi,
I have a method to render HTML from XSLT. Here is the method:
///
/// Method that renders HTML from XSLT document
///
/// <param name="writer" />
protected override void Render(HtmlTextWriter writer)
{
XPathDocument xdoc = new XPathDocument(Context.Server.MapPath(sourceFilePath));
XslTransform xslt = new XslTransform();
xslt.Load(Context.Server.MapPath(transformFilePath));
xslt.Transform(xdoc, null, writer);
}
I am now getting this warning:
warning CS0618: 'System.Xml.Xsl.XslTransform.Transform(System.Xml.XPath.IXPathNavigable, System.Xml.Xsl.XsltArgumentList, System.IO.TextWriter)' is obsolete: 'You should pass XmlResolver to Transform() method'
I need some help resolving this warning. Can you help?
Kyle
|
|
|
|