my code:
//read XML and append
XmlReader rdr = XmlReader.Create("parms.xml");
while (rdr.Read())
{
//get name and value to prepare clause
if (rdr.NodeType == XmlNodeType.Element)
{
switch(rdr.Name)
{
case "col":
whereClause += " AND " +
rdr.ReadElementContentAsString() + "=";
break;
case "val":
whereClause +=
rdr.ReadElementContentAsString();
break;
}
}
}
xml input:
<?xml version="1.0" encoding="utf-8"?>
<parameters>
<parm>
<col>
notice_of_violation.notice_of_violation_id
</col>
<val>
A1000125
</val>
</parm>
</parameters>
I'm puzzled. Any insight appreciated.
tia,
chance 5 1368
chance wrote:
my code:
//read XML and append
XmlReader rdr = XmlReader.Create("parms.xml");
while (rdr.Read())
{
//get name and value to prepare clause
if (rdr.NodeType == XmlNodeType.Element)
{
switch(rdr.Name)
{
case "col":
whereClause += " AND " +
rdr.ReadElementContentAsString() + "=";
break;
case "val":
whereClause +=
rdr.ReadElementContentAsString();
break;
}
}
}
xml input:
<?xml version="1.0" encoding="utf-8"?>
<parameters>
<parm>
<col>
notice_of_violation.notice_of_violation_id
</col>
<val>
A1000125
</val>
</parm>
</parameters>
I'm puzzled. Any insight appreciated.
Can you be more specific on what the problem is? You have four elements in
your XML, the second being <parm>. A quick test shows that element is read
fine using the code above. In fact, all four elements are read fine.
Please provide additional detail on the behavior you are seeing, and your
expected results.
--
Tom Porterfield
What function are you using to read the data?
When I use ReadElementContentAsString it is giving me back escaped
newlines which is screwing up my SQL clause....
Can someone suggest another?
On Mar 27, 10:27 am, "Tom Porterfield" <tppor...@mvps.orgwrote:
chance wrote:
my code:
//read XML and append
XmlReader rdr = XmlReader.Create("parms.xml");
while (rdr.Read())
{
//get name and value to prepare clause
if (rdr.NodeType == XmlNodeType.Element)
{
switch(rdr.Name)
{
case "col":
whereClause += " AND " +
rdr.ReadElementContentAsString() + "=";
break;
case "val":
whereClause +=
rdr.ReadElementContentAsString();
break;
}
}
}
xml input:
<?xml version="1.0" encoding="utf-8"?>
<parameters>
<parm>
<col>
notice_of_violation.notice_of_violation_id
</col>
<val>
A1000125
</val>
</parm>
</parameters>
I'm puzzled. Any insight appreciated.
Can you be more specific on what the problem is? You have four elements in
your XML, the second being <parm>. A quick test shows that element is read
fine using the code above. In fact, all four elements are read fine.
Please provide additional detail on the behavior you are seeing, and your
expected results.
--
Tom Porterfield- Hide quoted text -
- Show quoted text -
chance wrote:
When I use ReadElementContentAsString it is giving me back escaped
newlines which is screwing up my SQL clause....
The XmlReader methods do not escape strings, if they do anything then
they unescape XML escape mechanisms like character references (e.g.
to the character). Are you looking at the string in the Visual
Studio debugger? There you might get it displayed with e.g. \n but that
is just the way the debugger chooses to display the string.
--
Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/
chance wrote:
What function are you using to read the data?
When I use ReadElementContentAsString it is giving me back escaped
newlines which is screwing up my SQL clause....
Can someone suggest another?
I copied and pasted your code. As you didn't say what the exact problem was
and instead stated only that the second element was not being picked up, it
was unclear what you were trying to achieve. To have the returned string
not include whitespace characters, simply trim the string. Ex:
whereClause += " AND " + rdr.ReadElementContentAsString().Trim() + "=";
--
Tom Porterfield
Chance,
Is there some specific reason why you aren't doing something like this:
private void SerializeData_Click(object sender, EventArgs e)
{
XmlSerializer xs = new XmlSerializer(typeof(MyXmlData));
using (StreamWriter sw = new StreamWriter("Test.xml", false))
{
MyXmlData test = new MyXmlData();
test.Data.Add(new MyParm("column1", "value1"));
test.Data.Add(new MyParm("column2", "value2"));
test.Data.Add(new MyParm("column3", "value3"));
test.Data.Add(new MyParm("column4", "value4"));
xs.Serialize(sw, test);
}
}
private void DeserializeData_Click(object sender, EventArgs e)
{
XmlSerializer xs = new XmlSerializer(typeof(MyXmlData));
using (StreamReader sr = new StreamReader("Test.xml"))
{
MyXmlData test = xs.Deserialize(sr) as MyXmlData;
foreach(MyParm parm in test.Data)
{
MessageBox.Show(this, string.Format(
"Column {0} Value {1}", parm.Column, parm.Value));
}
}
}
Your datat object would look like this:
[XmlRoot("parameters", Namespace = "MyNameSpace")]
public class MyXmlData
{
[XmlElement("parm")]
public List<MyParmData = new List<MyParm>();
}
public class MyParm
{
private string _column;
private string _value;
public MyParm()
{
_column = string.Empty;
_value = string.Empty;
}
public MyParm(string column, string value)
{
Column = column;
Value = value;
}
[XmlElement("col")]
public string Column
{
get { return _column; }
set { _column = value; }
}
[XmlElement("val")]
public string Value
{
get { return _value; }
set { _value = value; }
}
}
Where you xml data would look like this:
<?xml version="1.0" encoding="utf-8"?>
<parameters xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="MyNameSpace">
<parm>
<col>column1</col>
<val>value1</val>
</parm>
<parm>
<col>column2</col>
<val>value2</val>
</parm>
<parm>
<col>column3</col>
<val>value3</val>
</parm>
<parm>
<col>column4</col>
<val>value4</val>
</parm>
</parameters>
Dave This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: lawrence |
last post by:
Is there an easy way to sort a 2 dimensional array alphabetically by
the second field in each row?
Also, when I use sort() on a two dimensional array, it seems to work a
lot like...
|
by: Ask Bjørn Hansen |
last post by:
Hi,
I am trying to control which element gets picked when I do a group by,
but I can't figure out how to do it.
First some example data:
CREATE TABLE t ( id int not null primary key...
|
by: Zombie |
last post by:
Hi all,
I wish to create a namespace other than the default one.
Let's say, the Schema looks like:
-----------------------------------------------------------------------
<?xml version="1.0"...
|
by: Anna |
last post by:
Hi all,
I posted the same question this afternoon but my message isn't showing up, so I thought I'd give it another try....
in case you should see it later I apologize for posting the same...
|
by: gogaz |
last post by:
Hi,
I am new to XML. Is following XML write? Or it can cause errors for
other developers using/parsing my XML output in their respective
applications.
<emp id="101" name="ABC">...
| |
by: Rajesh |
last post by:
Hello Everybody,
Can anybody help me to write a C program for finding the second largest
element in an array.
without using any sort algo. The array may conatin duplicate elements.
The algo...
|
by: Vortexmind |
last post by:
Hi all
I was wondering if this is possible in Javascript.
I want to make a bookmarklet. When a user launches it, it tells the
user to select an element in the page (for example a textarea) with...
|
by: desktop |
last post by:
How do I find the last element in the list numsx defined below?
int* myfind(int* arr_start, int* arr_end, int& s) {
int not_found = 666;
int* result = ¬_found;
while (arr_start !=...
|
by: caca |
last post by:
Hello,
This is a question for the best method (in terms of performance
only) to choose a random element from a list among those that satisfy
a certain property.
This is the setting: I need to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |