Insert / delete ?

Hi, im trying to first insert a node in the xml file and save it.

XmlDocument mDoc = new XmlDocument();
        mDoc.Load("struct.xml");


        XmlNode singleNode;
        XmlNode newNode = mDoc.CreateNode(XmlNodeType.Element, "page", "");
        XmlAttribute mAttr = mDoc.CreateAttribute("id");


        singleNode = mDoc.SelectSingleNode("//page[@id=\"" + pageid.Value + 
"\"]");

        if (singleNode == null)
        {
            Response.Write("no node found");
            return;
        }


        mAttr.Value = "100";
        newNode.Attributes.Append(mAttr);

        mDoc.DocumentElement.InsertAfter(newNode, singleNode);

i do find the node with ID number 3 and can retrive it contents, but i cant 
insert a new node after it.
Here is the xml file:
<?xml version="1.0"?>
<home>
     <page name="Test1" id="1">
          <page name="Pagetest1" id="2" src="test1.htm"></page>
          <page name="pagetest3" id="3" src="test2.htm"></page>
     </page>
     <page name="Test2" id="4" src="test1.htm">
          <page name="Test23" id="7" src="test1.htm">
               <page name="pagetest1" id="10" src="test1.htm"></page>
          </page>
          <page name="Pagetest1" id="5" src="test1.htm"></page>
          <page name="pagetest2" id="6" src="test1.htm"></page>
     </page>
</home>

The error message i am getting is:
Exception Details: System.ArgumentException: The reference node is not a 
child of this node.

Source Error:

Line 67: newNode.Attributes.Append(mAttr);

Line 68:

            Line 69: mDoc.DocumentElement.InsertAfter(newNode, singleNode);



Second question is, how do i delete a node ex. the node with ID nr 3?  what 
will happen if i delete node with id number 7?



-Patrick


0
floods (4)
6/28/2006 11:31:47 AM
dotnet.xml 7266 articles. 0 followers. Follow

2 Replies
342 Views

Similar Articles

[PageSpeed] 9


Patrick wrote:


>         singleNode = mDoc.SelectSingleNode("//page[@id=\"" + pageid.Value + 
> "\"]");
> 
>         if (singleNode == null)
>         {
>             Response.Write("no node found");
>             return;
>         }
> 
> 
>         mAttr.Value = "100";
>         newNode.Attributes.Append(mAttr);
> 
>         mDoc.DocumentElement.InsertAfter(newNode, singleNode);

Use
   singleNode.ParentNode.InsertAfter(newNode, singleNode);
You always have to call AppendChild or InsertAfter or InsertBefore on 
the new parent node where you want to append or insert the new child.

-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1777)
6/28/2006 12:04:53 PM

Patrick wrote:


> Second question is, how do i delete a node ex. the node with ID nr 3?  what 
> will happen if i delete node with id number 7?

Select the node using some DOM or XPath approach (e.g. SelectSingleNode) 
then do
   node.ParentNode.RemoveChild(node)

-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1777)
6/28/2006 12:06:20 PM
Reply:

Similar Artilces:

Deleting resource groups
Hi I need some advice in getting rid of resource groups from the service activity window. I had set up some people as a resource group but now i go to settings - business units - resource groups and i have deleted all those people or groups. However i still cant get rid of them in the service view. Any advice please would be helpful. Kind Regards Ridhima ...

Some deleted Recipient are not removed from GAL
Hi, Existing environment: WinNT 4.0 DC (with SP6a); Exchange 5.5 (with SP4) We have many (seven) Exchange 5.5 Sites within the same Organization. We have deleted some old users (recipient) from either of one site (few months ago). Updated the Recipient Update Services manually (RUS schedule set to "Run Always"). Only some site's GAL has been updated but certain site's GAL still shown the old users name. We only aware this problem lately. Anyway, we've tried to delete another few old users (recipient) from either of one site lately but there's been no problem...

Delete Records based on DoCmd.RunSQL
Hi I have a command button that when clicked deletes certain records from a subform based on an application number being equal. It deletes all records with the same applciation number as currently shown on the main form, see code below: DoCmd.RunSQL ("DELETE FROM tblAdultDetails WHERE [frmAdultDetails2].Form![ApplicationNum]=" + Str(Me.ApplicationNumber)) However I would like it to only delete records if the fields [MainApplicantFlag] =1 or [PartnerFlag] =1 as well as ApplicationNum being equal. These are both number fields btw. Can someone tell me what I should add to my code in...

How to insert and query nodes?
Hi all, I need to use XML to store some log data and then query that data. I'm struggling with the right terminology, which is hindering my ability to successfully search for a solution. Thanks in advance for your help! Two questions: 1. In VB.NET, how can I append new "Log" record to a "Site" record? 2. How can I query all of "Log" records in a single "Site" for an average "ResponseTime"? ------------------------------ <?xml version="1.0" standalone="yes" ?> <Sites> <Site Host="www.mysi...

Insert < & > on a delimited list
I want to insert the <> before and after the email addresses on a list of 2000 for import into Entourage. There must be an easy way. What might it be? Thanks, MARY::confused: -- maryrose ------------------------------------------------------------------------ maryrose's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=34579 View this thread: http://www.excelforum.com/showthread.php?threadid=543492 maryrose wrote: > I want to insert the <> before and after the email addresses on a list > of 2000 for import into Entourage. There must be an easy...

Best Practice for Automatically Inserting a Confidentiality Statement on Outgoing Mail
What is the best practice for including a statement of confidentiality on all outgoing mail? Using the signature feature or using a mail template? If you have Exchange server, the following article will help: http://www.slipstick.com/dev/sendform.htm If not, try this article instead: http://www.slipstick.com/addins/sig.htm -- Jocelyn Fiorello MVP - Outlook *** Replies sent to my e-mail address will probably not be answered -- please reply only to the newsgroup to preserve the message thread. *** In news:9CE75C34-C810-49DA-8B06-26B50CB1003F@microsoft.com, VBG wrote: > What is the ...

Special problem deleting a folder
2003/2007 (This has to do with PowerPoint VBA, but I'm asking here because theres a lot more VBA users here.) Is there a way to run a batch-like command line to delete a folder from within routine without calling to an external BAT or CMD file? I'm trying to simply delete some folders within which is an addin that my code already unloaded and removed and unregistered, and now I want its folders deleted (within the same PPT session that started the macro). But PPT holds on to the addin file thinking it's still being used (which it's not) and won't let RmDir or Ki...

Easy way to delete columns?
I've got a workbook with 5 sheets in it. Each sheet has a large number of columns. On some of the columns, there is no data on the whole sheet except for row 1 (the header, or title of the column). Is there an easy way I can tell Excel to remove the columns that have no data on any row (except row 1)? Excuse my ignorance, I'm not sure if there is some backend interface or "language" (like SQL maybe?) or something that could take care of something such as this. -ee99ee On each sheet, assuming you can use row 2 to determine delete / not delete based on blank / not blank. S...

I cannot delete old e-mails or find "inbox repair" to fix it.
I get an error message relating to errors in outlook.pst and to use the inborx repair and run the scanpst.exe . This does not work because i cannot find the repair box by doing a search, and the scanpst.exe doe not even work in the run box. This microsoft solution is crap. I need help bad because I now have 75 e-mails I need to delete and the number is growing daily. HELP! Stating scanpst.exe doesn't work doesn't tell anybody anything, unless you state the errors it produced The data file, by default outlook.pst, is a hidden file, you have to search to include hidden, if thats ...

Deleting Blank Rows #2
The problem is there is a blank rows between blocks of data (37 blocks of data) I want to be able to delete the blank rows... the blank rows can vary each month... thanks -- Reeni Hi Reeni, Assuming that the blank rows are determined by blank cells in column A, try the following macro: '=============>> Public Sub Tester1() On Error Resume Next Columns("A").SpecialCells(xlCellTypeBlanks). _ EntireRow.Delete End Sub '<<============= If you are new to macros, you may wish to visit David McRitchie's 'Getting Started With Macros ...

Macro to Count and insert values
Hello all, I am trying to write a macro that will run from a vb6 application as part of a report function. The report includes 18 columns including InvoiceNumber and ItemNumber. I am having a hard time explaining what I need. I am going to give an example of what I need instead... InvoiceNumber ItemNumber InvoiceCount ItemCount Invoice1 Item1 1 1 Invoice1 Item2 1 2 Invoice1 Item3 1 3 Invoice2 Item1 2 ...

Deleted account is still in the database
I have Money Plus Deluxe and I have enabled downloading from my institution. My investment institution has several accounts, but I am tracking only a couple of them. Some new accounts then were added at the institution and when I downloaded additional “new” accounts were created automatically with transactions pending. I disabled the online download which terminated the statements with the new account. The new account was then deleted and the online download re-enabled and selected which accounts to download. The problem remains that even though the account is deleted, under Port...

Issue with inserting an Access database to Word
I'm attempting to insert a shared Access database into Word using the Word "Insert Database" tool. I select the database query to run from, limit the fields, and insert the data - then I get an hourglass for a bit and when that's done I get nothing... not even an error message. There is data in the fields I'm pulling (I double-checked). The Word document at that point acts like I've changed it (requests a save on close), but there is no data on the screen. This process works when I create a local copy of the database that no other user is in, but ...

Deleting/Creating a relationship between two tables -----> Help Pl
Hi all: I would like to know how to break and create a relationship between two tables. I have created a database to handle the capturing of out inventory stock count/take. Part of the setup routine is creating tables in the database from the tables in our accounting system. I must recreate them each time the database is used to capture the current inventory levels as well as any new items created since our last inventory count from our accounting system. In order for me to do this I must manual remove the relationships between the two tables, run the set up program to cre...

auto insert footer to master documents
I need to know how to get the file name to automatically insert as a footer on a master document and print out each time without having to add a footer.I need step by step instructions. Thanks -- Heather Janek Office Assistant Can't be done automatically. -- JoAnn Paules MVP Microsoft [Publisher] Tech Editor for "Microsoft Publisher 2007 For Dummies" "Heather Janek" <HeatherJanek@discussions.microsoft.com> wrote in message news:4920C076-2975-4762-A497-0EE0DB918241@microsoft.com... >I need to know how to get the file name to automatically insert as a ...

How to delete a global customer in RMS?
I get a message "the customer is a Global Customer and cannot be deleted" when trying to delete the customer in RMS Manager. Any ideas on how to delete or take care of this problem?? JWT wrote: > I get a message "the customer is a Global Customer and cannot be deleted" > when trying to delete the customer in RMS Manager. Any ideas on how to > delete or take care of this problem?? You can't delete from RMS the global customer.. you can remove from HQ global customer but from store no :) .. two solution: 1) Remove flag 'GlobalCustomer' from custom...

External web query
I am not a programmer and a new excel user. I have an external web query that I am using tracking external links from a web site. I need to create an additional column with the web page info that relates to where the link is coming from. I tried but when I refresh the data it inserts cells with the any new links listed but then that throws off my additional column info. I looked in Data Range Properties and checked the middle option but that doesn't work the way I thought it would. Suggestions? -- Message posted via http://www.officekb.com ...

Change inserted calendar year
Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) Processor: Intel Hi... I would like to insert TWO calendars in a WORD document. I can do that but how do I change the year &amp; month dates? I would like to have (for instance) a May 2010 and a separate June 2010 calendars. Muy inserts keep coming up as 2006! <br> Thanks, Jack ...

Deleteing some Rows
I am looking for some help to delete the rows in a sheet which have some Specific words in the cell. For example: i have sub total for every 10 to 15 lines and would like to find out the cell which have "sub total" word int it and delete the whole row. Thanks in advance One way: Sub DeleteRow() 'Adapted from Microsoft code found at 'msdn.microsoft.com Dim sFind As String Dim Rng As Range Dim sFindRow As Long sFind = "*sub*total*" Set Rng = Range("A:A").Find(What:=sFind, lookat:=xlWhole) While Not Rng Is Nothing sFindRow = Rng.Row Rng.EntireRo...

Delete Rows from sheet 1 from values in sheet 2
Hi, Sheet 2 has the values A B 1 CAR BUS 2 3 Sheet 1 Has A B 1 BUS 2 TRAIN 3 CAR 4 BIKE 5 BUS I want to programatically select as a range CAR BUS (sheet 2) and delete other entire rows in sheet 2 i.e A B 1 BUS 2 CAR 3 BUS Thanks for all future help -- Message posted via OfficeKB.com http://www.officekb.com/Uwe/Forums.aspx/excel-programming/200911/1 dim source as range dim basedata as string set source =...

Fill handle use is inserting a row
Not sure what happened or if I changed setting, but when I try to use the fill handle and fill a formula to the next row, it inserts a new row. Any ideas on how to fix this? thank you. This probably isn't it, but just in case -- is it possible you have a sticky Shift key? That's what happens (inserting a row) when I Shift- Drag the fill handle. But you probably would have noticed the different mouse pointer if that was the case. Greg Lovern http://PrecisionCalc.com On Jan 31, 12:41=A0pm, Keb <K...@discussions.microsoft.com> wrote: > Not sure what happened...

Category will not Delete / Category changes when email moves to Trash folder
My email is imap. Deleted emails are directed to the Trash folder. All in coming emails are received with the Category of =93None=94 (no Rules). Recently when emails are Deleted from the In Box and transferred into the Trash folder Entourage changes those emails to the Category named eBay (one of my Categories) from None. If the destination folder is redefined, the problem goes away. The odd thing is when I go to Edit / Category / Edit Categories the Category named eBay can be edited or duplicated, but not Deleted. (Button does not activate) All other Categories act normal. Because ...

Delete item at Store
I have 2 Store and HQ. But I can't Access Store directly. Anyway, I want to Delete One item at HQ and store. I do that at HQ. But I can't do that at Store. Because Store are in another area How Can i Do that? It's generally better to make the item inactive if at all possible. If you abosolutely must delete the item, you can use a Worksheet 51 to run the following SQL: DELETE from Item WHERE ItemLookupCode = 'X' Where X is the Item Lookup Code for the item you want to delete. Again, if there are any transactions associated with the item in question, it would be bes...

Cannot insert duplicate key in object 'SY60100'
Using Great Plains 7.0. During Create Company process - trying to add one company, I received an error during the very last step of "Create Company Information". The error is: [Microsoft][ODBC SQL Server Driver][SQL Server]Violation of PRIMARY KEY constraint 'PKSY60100'. Cannot insert duplicate key in object 'SY60100'. make sure that the DYNAMICS database is owned by DYNSA make sure that the TWO database, if present is owned by DYNSA. THis you will have to check by using SQL enterprise manager or Query Analyzer. ------ Robert "mrosa" <mrosa@ProfitL...

Deleting Duplicate Entries in a list.
I am working with a list of people and addresses, a registered voter list. For a mailing, is there a way to delete the duplicate addresses so I will only send one letter to each household? Thanks Scott Here is a write-up I have on what you want to do. HTH Otto Before you run the macro, you must sort your data a-z so that all the duplicate entries appear sequentially. The macro works by comparing the value in each row with the value in the preceding row (i.e. is this cell contents the same as the cell above?). If so it deletes the row and continues. This macro is written for da...