Groups | Blog | Home
all groups > dotnet xml > september 2006 >

dotnet xml : ReadXML Illegal characters in path


webmaster NO[at]SPAM 1stmiami.com
9/23/2006 8:13:19 AM
Getting error: Illegal characters in path
what's wrong with this?

string xmlSR =
"<XmlDS><table1><phone>Value1</phone><name>jake</name></table1></XmlDS>";
myDataSet.ReadXml(xmlSR, XmlReadMode.IgnoreSchema);
DataList5.DataSource = myDataSet;
DataList5.DataBind();

Also, what's the best way to return XML from a method for binding into
a web control?

myDataSet.ReadXml(x.y(), XmlReadMode.IgnoreSchema);

I'm trying this, but it's resulting in error about no datasource, also,
its only returning the first row:

public static string yt()
{
string conn = "Data
Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\xx.mdf;Integrated
Security=True;User Instance=True";
using (SqlConnection connection = new SqlConnection(conn))
{
connection.Open();
SqlCommand cmd = new SqlCommand("select * from book2 for
xml path", connection);
cmd.CommandType = CommandType.Text;
XmlReader xr = cmd.ExecuteXmlReader();
xr.MoveToContent();
return(xr.ReadOuterXml());
webmaster NO[at]SPAM 1stmiami.com
9/23/2006 8:53:44 AM
newbie here trying to piece this together

now getting:

DataBinding: 'System.Xml.XmlElement' does not contain a property with
the name 'phone

at the control:

<asp:DataList ID=3D"DataList5" runat=3D"server" Style=3D"z-index: 110;
left: 362px; position: absolute;
top: 10px" Width=3D"152px" BackColor=3D"#DEBA84"
BorderColor=3D"#DEBA84" BorderStyle=3D"None" BorderWidth=3D"1px"
CellPadding=3D"3" CellSpacing=3D"2" GridLines=3D"Both">
<ItemTemplate>
1:
<asp:Label ID=3D"PhoneLabel" runat=3D"server" Text=3D'<%#
Eval("phone") %>'></asp:Label><br />
2:
<asp:Label ID=3D"Label3" runat=3D"server" Text=3D'<%#
Eval("name") %>' Width=3D"105px"></asp:Label> <br />
</ItemTemplate>


trying code:

string xx =3D
"<root><phone>Value1</phone><name>jake</name></root>";
XmlDocument d =3D new XmlDocument();
d.LoadXml(xx);
DataList5.DataSource=3Dd.SelectNodes("/root/*");
DataList5.DataBind();






[quoted text, click to view]
e/
webmaster NO[at]SPAM 1stmiami.com
9/23/2006 9:13:53 AM
I am experimenting. My eventual goal is bind from a web service that
will return an xml dataset. The webmethod must return xml as I"m not
sure if the clients will always be .net or sql server or ado.net. Im
still stuck. Please see my prior post, seems my issue is not formating
of the xml. Thanks!


[quoted text, click to view]
webmaster NO[at]SPAM 1stmiami.com
9/23/2006 9:31:15 AM
okay. I did that and IT WORKED!

myDataSet.ReadXml(t2.G2());
DataList5.DataSource = myDataSet;
DataList5.DataBind();




public class t2
{
public static XmlReader G2()
{
string conn = "Data Source=....";
using (SqlConnection connection = new SqlConnection(conn))
{
connection.Open();
SqlCommand cmd = new SqlCommand("select * from book2 for
xml RAW", connection);
cmd.CommandType = CommandType.Text;
XmlReader xr = cmd.ExecuteXmlReader();
return (xr);


Thing is though.. I want the the eventual web sevice return the lowest
common demominator as I don't know what will try to consume it. Any
suggestions?



[quoted text, click to view]
webmaster NO[at]SPAM 1stmiami.com
9/23/2006 10:29:03 AM
DataSet myDataSet = new DataSet();
myDataSet.ReadXml = new StringReader(test.Gogetit());

results in error:

Error 1 Cannot assign to 'ReadXml' because it is a 'method group'


public class test
{
public static string Gogetit()
{
string conn "..."
using (SqlConnection connection = new SqlConnection(conn))
{
connection.Open();
//SqlCommand cmd = new SqlCommand("select * from book2 for
xml path", connection);
SqlCommand cmd = new SqlCommand("select * from book2 for
xml RAW", connection);
cmd.CommandType = CommandType.Text;
XmlReader xr = cmd.ExecuteXmlReader();
xr.MoveToContent();
return(xr.ReadOuterXml());





[quoted text, click to view]
webmaster NO[at]SPAM 1stmiami.com
9/23/2006 10:56:51 AM
okay, that worked.

my method seems to have a bug, and I'm kinda newbie. it's only
returning the first

<row name="somename" phone="somephone" />

but binding is working.

if I change the select to use for xml path It looks like this and also
works:

<row><name>somename</name><phone>somephone</phone></row>

What's recommended for cross platform any consumer use of xml? I'm sure
when I turn it into a service there will be an added layer of confusion
for me.

Thanks!

[quoted text, click to view]
Bjoern Hoehrmann
9/23/2006 5:30:37 PM
* webmaster@1stmiami.com wrote in microsoft.public.dotnet.xml:
[quoted text, click to view]

Presumably ReadXml does not take a XML string but the path to a XML file
which the above is not since it has illegal characters that cannot occur
in a path.
--
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
Martin Honnen
9/23/2006 6:01:08 PM


[quoted text, click to view]

You should pass in a string with a URL as the first argument to ReadXml.
At least that is one option. You can also pass in an XmlReader and based
on what you have shown that is what you want to do, simply let your
method return that reader that ExecuteXmlReader gives you, then pass
that reader to ReadXml
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataDataSetClassReadXmlTopic4.asp>
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataDataSetClassReadXmlTopic8.asp>


On the other hand you seem to have relational data, then you let the
data base convert and return that as XML, then you load the XML into a
DataSet (which is again a relational view of the data). Maybe you are
just experiementing and playing with the different APIs, but if not I am
not sure why you let the data base return XML at all, you can simply
make a normal SQL query and load that result in a DataSet.


--

Martin Honnen --- MVP XML
Martin Honnen
9/23/2006 7:02:04 PM


[quoted text, click to view]


[quoted text, click to view]

There is microsoft.public.dotnet.framework.aspnet.webservices to discuss
web services.

In terms of the DataSet ReadXml method it is also possible to read in a
string with XML e.g.
aDataSet.ReadXml(new StringReader(stringWithXml))
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataDataSetClassReadXmlTopic3.asp>

--

Martin Honnen --- MVP XML
Martin Honnen
9/23/2006 7:37:11 PM


[quoted text, click to view]


[quoted text, click to view]

Use what I posted, I did not tell you to try to assign to ReadXml, you
should call it as shown.


--

Martin Honnen --- MVP XML
John Saunders
9/24/2006 2:19:19 PM
[quoted text, click to view]

I suggest that you should not return .NET - specific data types from a web
service if you expect clients which are not running .NET.

The lowest common denominator would be XML. You should define the XML using
a schema, and you should return XML which matches this schema. If you happen
to use a DataSet to create the retuned XML, that's great. But don't return a
DataSet and then expect Java to understand it.

John

AddThis Social Bookmark Button