|
I am trying to insert new nodes within an existing XML document. The insert that I am having problems with is a few nodes deep.
I can insert a new node just below the root node with the following with no problems:
<br />
XmlDocument doc = new XmlDocument();<br />
doc.Load(strXMLPath);<br />
<br />
XmlNode tasks = doc.SelectSingleNode("/tasks");<br />
doc.AppendChild(tasks);<br />
<br />
Now, here is the code which tries to write a little deeper down and is breaking:
<br />
XmlDocument doc = new XmlDocument();<br />
doc.Load(strXMLPath);<br />
<br />
XmlNode checks = doc.SelectSingleNode("/tasks/task[@id='1001']/checks");<br />
doc.AppendChild(checks);<br />
<br />
The error the second code snippet gives is: This document already has a DocumentElement node. It gives this error on the doc.AppendChild(checks); line
I just can't figure it out. I did a quick watch on XmlNode checks = doc.SelectSingleNode("/tasks/task[@id='1001']/checks"); and it did put me in the correct node.
I have no idea why I can not append into this node. Anyone have any ideas?
Here is my XML doc if you want to see it for reference:
<br />
<?xml version="1.0" encoding="utf-8"?><br />
<tasks><br />
<task id="1000"><br />
<name>Task Name</name><br />
<checks><br />
<check id="1000_1"><br />
<time>14:00</time><br />
</check><br />
<check id="1000_2"><br />
<time>23:00</time><br />
</check><br />
</checks><br />
</task><br />
</tasks>
|
|
|
|
|
Why would you want to append the same node that you queried?
I would suggest the following:
XmlNode checks = doc.SelectSingleNode("/tasks/task[@id='1001']/checks");
XmlNode newCheck,newNode;
newCheck = doc.CreateElement("check");
XmlAttribute attr = doc.CreateAttribute("id");
attr.Value = "1000_3";
newCheck.Attributes.Append(attr);
//add child node of new check
newNode = doc.CreateElement("time");
newNode.Value = "15:00";
newCheck.AppendChild(newNode);
checks.AppendChild(newCheck);
|
|
|
|
|
Hello,
I am trying to modify an XML file by adding a new element in the middle.
I've managed to add something using:
Set objNewNode = MyXMLDOM.createElement("Element")
Set objNewText = MyXMLDOM.createTextNode("<item>1</item1>")
objNewNode.appendChild(objNewText)
Set objCurrNode = MyXMLDOM.documentElement
objCurrNode.appendChild(objNewNode)
MyXMLDOM.save filenamePath
This adds it to the document root at the end, how do I add it in the middle using a path? I'm sure I need to set objCurrNode differently but I can't find out how.
Many thanks
|
|
|
|
|
|
hello here is my problem
i using an xml file to store some strings
i wanted to use certain characters in the strings to denote colors
however the characters i used where invalid characters
for example
<name>&+RSteve&n
i assume the invalid char is either the & or the +
is there anyway i can still use these chars in my strings?
|
|
|
|
|
|
I would like to try out the online quiz found at
http://www.codeproject.com/aspnet/xmlquiz.asp[^]
I have downloaded the code and uploaded it to my site but i dont know what file to open the quiz or if i have to create an html file to run it.
I am new at this and qould appreciate any help.
Thanks in advance
Dan
|
|
|
|
|
hi, in general you should use article's very own forum at the bottom of the page. OK, here it looks like author doesn't response for a while so be it. As I understand from article there is .aspx page... so it's like with every ASP.NET application. Fist you have to set virtual directory in IIS and then (assuming you have installed .NET framework and ASP.NET) you simply type URL to virtual directory into browser (e.g. http://localhost/quiz or something) and it should work. If it doesnt, try include .aspx file into url - somethimes there is not set default page or your page is not named as default page should be (usualy default.aspx or index.aspx).
hope it helps
David
Never forget: "Stay kul and happy" (I.A.)
David's thoughts / dnhsoftware.org / MyHTMLTidy
|
|
|
|
|
I am writing a compact framework application that stores data in an XML file. Consiquently I have to read and write and edit the data that is stored in this file. Reading and searching the data is easy enough however I am looking for the most efficient way to edit the data once stored.
The solution that I have seen suggested most often is to use XmlDocument to open the file and edit it. However I have seen it written that the fact that XmlDocument requires the entire document to be read into memory is in efficient and a bad idea with memory restricted devices such as a PDA.
This leads me to have the following questions:
Is the performance issues of XmlDocument a large concern if I am going to be opening the file, finding what I am looking for editing and closing all at once?
Secondly, if the answer to that question is true, what is the best way to edit a file? My next thought would be to use a conjunction of XmlTextReader and XmlTextWriter to search the file and push into a buffer as I go, but that seems tedious.
Many thanks for your time and advice,
Andy
|
|
|
|
|
|
Hi
1) Is it possible to take the "PrintScreen" of the windows currently running on the system, at some regular invervals, and save them into image files(*.bmp/*.gif/*.jpeg)?
2) From keyboard, when i press any key i can get the KeyCode, but when i press "Print Screen" button, i am unable to get the KeyCode in the Form_KeyDown(). What is the reason?
Vamshidhar K
Vamshidhar K
|
|
|
|
|
I don't think your question belongs to this forum. You should try the MC++ or C# forums since this should be mainly XML/XSLT related questions.
~Javier Lozano
(blog)
|
|
|
|
|
I want to load a xml file and use ASP to diplay all separate tags and values in the xml file (to load all fields and values into memory / array).
Can someone give me an easy script to do this? I've been looking on Google but found no simple solution.
|
|
|
|
|
make a xsl file with all the ur tags
make one style sheet for it and include it in the xsl
to display all the tags and values do this in the xml file
use alias for ur xsl file in the tag <x:stylesheet xmlns:x=" ">
<x:template match="/name of xsl file">
<x:for-each select="name of the record what ever u have given in ur xsl">
<x:value-of select="name of the tag ">
repeat it for all tags
happy
TripathiH
|
|
|
|
|
Hello,
i want to generate a xml string using a DTD in VC++. can anyone help.
iam provided with a DTD, basically i need to create a xml string and send using http/post mthod.
Gp
|
|
|
|
|
Hi,
I have a webservice in c# that returns a dataset !
I want to populate in a vb60 application a recorset with the information of Dataset !!
The webservice is working fine but i dont know how to populate the recordset with the dataset information !!
|
|
|
|
|
Hello,
I have an XML file that has no DOCTYPE decleration in it.
But I have to validate it with an external DTD file. I am using Xerces C++ 2.6.
Is there any way to do that with outediting the XML file (like setting DocumentType before parsing)?
Any help will be greately appreciated.
Thanks,
|
|
|
|
|
Hi,
Please help me out in solving the problem. I retrived the data from SQL Server 2000 using SQLXML. I have created an XSD. Now, I have to convert the dataset into XML based on the XSD. While doing so, I get the following error:
"MSXML: is an invalid or unsupported XPath "
I installed MSXML 4.0 SP2, still I couldn't find the solution.
test.xsd is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:sql="urn:schemas-microsoft-com:mapping-schema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="Limit" sql:relation="SM_Limit_Type">
<xs:complexType>
<xs:sequence>
<xs:element name="LT_LimitType_Name" type="xs:string" sql:field="LT_LimitType_Name"/>
<xs:element name="LT_Country_ID" type="xs:int" sql:field="LT_Country_ID"/>
<xs:element name="LT_Active" type="xs:int" sql:field="LT_Active"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
On Page_Load, I give the following code...
SqlXmlCommand xmlCom = new SqlXmlCommand("Provider=SQLOLEDB;server=servername;user id=sa;pwd=;database=dbname");
Stream strm;
StreamReader strmRead;
XmlDocument xmlDoc=new XmlDocument();
string strXml;
xmlCom.CommandText="SELECT LT_LimitType_Name, LT_Country_ID, LT_Active FROM SM_Limit_Type WHERE LT_LimitType_ID = 2";
xmlCom.CommandType=SqlXmlCommandType.XPath;
xmlCom.SchemaPath=path+@"test.xsd";
xmlCom.RootTag="RootElement";
strm=xmlCom.ExecuteStream();
strmRead=new StreamReader(strm);
strXml=strmRead.ReadToEnd();
xmlDoc.LoadXml(strXml);
Please help me out in finding the solution. Thanks in advance...
Sarun
Please rate this page...
|
|
|
|
|
Since you are using SQLXML and your CommandType is an XPath expression, setting an SQL statement for your CommandText property is invalid.
Thus the reason you get the 'invalid or unsupported XPath' message. Instead, you need to have an XPath expression to query agaisnt SQL Server using your given schema.
Try this expression:
xmlCom.CommandText = "Limit[LT_LimitType_ID = 2]";
~Javier Lozano
(blog)
|
|
|
|
|
Hi,
Thanks a lot Mr. Javier Lozano. That problem is solved. I want to know one more thing.
I am using a stored procedure to retrieve data. Now, the dataset I receive should be linked with the XSD to get the XML in the format specified in the schema. How can I do it? Now what I am doing is I call the SP, insert the data I get from the procedure to a table, and bind this table as the sql:relation in XSD, something like this...
<xs:element name="Limit" sql:relation="tab_SS_Limit_Type_Retrieve">
In the webservice file I give the command as follows...
SqlXmlCommand xmlCom = new SqlXmlCommand("Provider=SQLOLEDB;server=servername;user id=sa;pwd=;database=dbname");
SqlConnection sqlconn=new SqlConnection("server=servername;user id=sa;pwd=;database=dbname");
SqlCommand sCmd=new SqlCommand("insert into tab_SS_Limit_Type_Retrieve EXEC SS_Limit_Type_Retrieve 2",sqlconn);
xmlCom.RootTag="RootElement";
xmlCom.CommandText="Limit";
CommandType=SqlXmlCommandType.XPath;
xmlCom.SchemaPath=@"test.xsd";
Here I am using two connections, one for SQLCommand and the other for SQLXmlCommand. I am getting the result, but I dont think this is the right way. Can you suggest me the optimum way to do the same?
Thanking you,
Sarun
|
|
|
|
|
HI,
has anyone tried sending a WAP Push using Multipart/Related XML in ASP.NET before?
I have tried to send but the PAP Gateway can't seems to accept it.
Any help is appreciated.
|
|
|
|
|
Hello all,
I'm populating a strongly typed dataset from a local XML file and I would like to establish a master-detail relationship between an element and a table of grandchild elements (and their attributes) which will be bound to a datagrid. Is it possible to do this without clicking through the child element on the datagrid? The XML file will be populated with multiple grandchild elements for each grandparent. Any help would be much appreciated (in C# if possible). Thanks.
-CS
|
|
|
|
|
could anyone of u possibly tell me how to use Xquery with ASP 3.0 or if not then how do i actually use it.
Regards
Wilbur
|
|
|
|
|
My Ques: How to set Table hint and Row hint in the
following example. Pl help me urgent
one. I want to create a crystal report using the
XML file. so i need the Table Hint and Row Hint
Values
<cube strategydesc="Gse" strategyname="dots"
="" dataentry="E" entityname="ALDI" entitydesc="ALDI">
<desc>
- <levelnode name="Exp" lvlid="1" edit="False">
<desc>customer.
- <levelnode name="Fea" lvlid="1.1" edit="False">
<desc>The Features
- <levelnode name="Mix" lvlid="1.1.1" edit="True">
<desc>how
- <levelnode name="High" lvlid="1.1.1.1" edit="False"
="" projection="1" key="Ad" relation="Coll">
<desc>The
|
|
|
|
|
My Ques: How to set Table hint and Row hint in the
following example. Pl help me urgent
one. I want to create a crystal report using the
XML file. so i need the Table Hint and Row Hint
Values
<cube strategydesc="Gse" strategyname="dots"
="" dataentry="E" entityname="ALDI" entitydesc="ALDI">
<desc>
- <levelnode name="Exp" lvlid="1" edit="False">
<desc>customer.
- <levelnode name="Fea" lvlid="1.1" edit="False">
<desc>The Features
- <levelnode name="Mix" lvlid="1.1.1" edit="True">
<desc>how
- <levelnode name="High" lvlid="1.1.1.1" edit="False"
="" projection="1" key="Ad" relation="Coll">
<desc>The
|
|
|
|