Microsoft
Software
Hardware
Network
Question : C# XML data showing System.Xml.XmlElement instead of the values
I have a C# application that reads in an XML file and build an array of objects which contain values from that XML file. Unfortunately, while it works in asp and in vb, it is not returning the values in the click event. The syntax of the xml should be "close" and I haven't a clue what is the holdup. Below are the relevant pieces.
Please advise.
Thanks,
Howard
XmlNodeList LoadNodeList (String sXMLFile, String sNodeSelector)
{
XmlDocument objXML = new XmlDocument();
objXML.Load (sXMLFile);
return objXML.SelectNodes (sNodeSelector);
}
void AppInit()
{
XmlNodeList objNodeList = null;
XmlNodeList objDataConnectionNodeList = null;
int nCnt, nCnt2;
objNodeList = LoadNodeList (m_XMLFileName, "//Reconcile_DataSets/Reco
rdSets/Rec
Set");
nCnt = objNodeList.Count;
cRec = new cReconciling[nCnt];
for (int nlp=0; nlp
{
cRec[nlp]= new cReconciling();
}
for (int nlp=0; nlp
{
cRec[nlp].Name = objNodeList.Item(nlp).Sele
ctSingleNo
de("Name")
.ToString(
);
cRec[nlp].Author = objNodeList.Item(nlp).Sele
ctSingleNo
de("Author
").ToStrin
g();
cRec[nlp].Description = objNodeList.Item(nlp).Sele
ctSingleNo
de("Descri
ption").To
String();
cRec[nlp].theDate = objNodeList.Item(nlp).Sele
ctSingleNo
de("Date")
.ToString(
);
nCnt2 = objNodeList.Item(nlp).Sele
ctNodes("D
ataConnect
ion").Coun
t;
cRec[nlp].SizeDataConnecti
onList (nCnt2);
objDataConnectionNodeList = objNodeList.Item(nlp).Sele
ctNodes("D
ataConnect
ion");
for (int nlp2=0; nlp2
{
cRec[nlp].DataConnectionLi
st(nlp2).S
erverName = objDataConnectionNodeList.
Item(nlp2)
.SelectSin
gleNode("S
ERVER_NAME
").ToStrin
g();
cRec[nlp].DataConnectionLi
st(nlp2).D
atabaseTyp
e = objDataConnectionNodeList.
Item(nlp2)
.SelectSin
gleNode("D
ATABASE_TY
PE").ToStr
ing();
cRec[nlp].DataConnectionLi
st(nlp2).D
atabaseNam
e = objDataConnectionNodeList.
Item(nlp2)
.SelectSin
gleNode("D
ATABASE_NA
ME").ToStr
ing();
cRec[nlp].DataConnectionLi
st(nlp2).U
ID = objDataConnectionNodeList.
Item(nlp2)
.SelectSin
gleNode("U
ID").ToStr
ing();
cRec[nlp].DataConnectionLi
st(nlp2).P
WD = objDataConnectionNodeList.
Item(nlp2)
.SelectSin
gleNode("P
WD").ToStr
ing();
cRec[nlp].DataConnectionLi
st(nlp2).S
QL_Header = objDataConnectionNodeList.
Item(nlp2)
.SelectSin
gleNode("S
QL_HEADER"
).ToString
();
cRec[nlp].DataConnectionLi
st(nlp2).S
QL = objDataConnectionNodeList.
Item(nlp2)
.SelectSin
gleNode("S
QL").ToStr
ing();
cRec[nlp].DataConnectionLi
st(nlp2).O
utputFolde
r = objDataConnectionNodeList.
Item(nlp2)
.SelectSin
gleNode("O
UTPUT_FOLD
ER").ToStr
ing();
cRec[nlp].DataConnectionLi
st(nlp2).O
utputFileN
ame = objDataConnectionNodeList.
Item(nlp2)
.SelectSin
gleNode("O
UTPUT_FILE
NAME").ToS
tring();
}
}
}
void cmdReadClick(object sender, System.EventArgs e)
{
String CRLF = Environment.NewLine;
String sHeader = "";
txtData.Text = txtData.Text + sHeader + CRLF;
int nRecs=2;
txtData.Text = "";
for (int nlp=0; nlp
{
sHeader = "<<<" + "*************************
**********
**********
*******" + ">>>" + CRLF;
txtData.Text = txtData.Text + sHeader + CRLF;
sHeader = "<<<" + "***************" + cRec[nlp].Name.ToString() + "***************" + ">>>";
txtData.Text = txtData.Text + sHeader + CRLF;
sHeader = "<<<" + "*************************
**********
**********
*******" + ">>>" ;
txtData.Text = txtData.Text + sHeader + CRLF;
String sAccSQL = "", sAccHeader="";
for (int nlp2=0; nlp2
ionCount; nlp2++)
{
sAccSQL = "SQL=" + cRec[nlp].DataConnectionLi
st(nlp2).S
QL.ToStrin
g() + CRLF;
sAccHeader = "SQL_HEADER=" + cRec[nlp].DataConnectionLi
st(nlp2).S
QL_Header.
ToString()
+ CRLF;
txtData.Text = txtData.Text + sAccSQL + sAccHeader + CRLF + "*************************
**********
**********
*****" + CRLF;
}
}
}
Answer : C# XML data showing System.Xml.XmlElement instead of the values
My mistake - I'm used to working with XPath navigators. I think what you need is:
objNodeList.Item(nlp).Sele
ctSingleNo
de("Name")
.InnerText
Random Solutions
Rank records in an Access Dbase by date
Dynamics GP Web Services PHP
Fonts not showing in fontlist
How do i import data from Visual FoxPro 6.0 DB to Access 2003 with VBA
Insert File VBA issues with Styles
Combine multiple Excel sheets into one sheet
Help! I'm getting an OleDbException: No error message available, result code: E_FAIL(0x80004005), trying to open an oleDBConnection to an Excel file.
Share resource fails to bring online
localhost/certserv doesnt work, says that the page cannot be found
how to configure my SMTP server for outgoing verizon