XmlDocument and XmlNode

Hi,
I've loaded an XmlDocument from a file XML: this file has many similar 
XmlNode and it is difficult to select them by using SelectSingleNode of the 
object XmlDocument.

I've this question: is it possible to identify each XmlNode of the 
XmlDocument by using an inner key or something like that ?
I precise that I 'm not allowed to change the file XML, therefore I can't 
add any key element or attribute in each node.

Thank in advance
0
SIU (13)
11/23/2004 12:43:02 PM
dotnet.xml 7266 articles. 0 followers. Follow

3 Replies
534 Views

Similar Articles

[PageSpeed] 42


Siu wrote:


> I've loaded an XmlDocument from a file XML: this file has many similar 
> XmlNode and it is difficult to select them by using SelectSingleNode of the 
> object XmlDocument.
> 
> I've this question: is it possible to identify each XmlNode of the 
> XmlDocument by using an inner key or something like that ?
> I precise that I 'm not allowed to change the file XML, therefore I can't 
> add any key element or attribute in each node.

If you have unique id attributes in the document then you can use 
GetElementById. XPath also has an id function. But that of course 
requires that you have a DTD or schema declaring attributes of type ID 
and the elements have a unique id attribute value.

If you need to have keys you might want to look into XSLT, it has the 
<xsl:key> instruction and the key function.

-- 

	Martin Honnen
	http://JavaScript.FAQTs.com/
0
mahotrash (1778)
11/23/2004 12:50:39 PM
Hi Siu

If you had a document like this:

<Root>
  <Child>A</Child
  <Child>A</Child>
</Root>

even though the name and content of the Child elements is the same, you can 
use a positional predicate in your XPath expression to select each one in 
turn: for example /Root/Child[1] and /Root/Child[2]. Will that approach not 
work for your documents?

HTH

Nigel Armstrong

"Siu" wrote:

> Hi,
> I've loaded an XmlDocument from a file XML: this file has many similar 
> XmlNode and it is difficult to select them by using SelectSingleNode of the 
> object XmlDocument.
> 
> I've this question: is it possible to identify each XmlNode of the 
> XmlDocument by using an inner key or something like that ?
> I precise that I 'm not allowed to change the file XML, therefore I can't 
> add any key element or attribute in each node.
> 
> Thank in advance
0
11/23/2004 2:39:03 PM
Thanks Nigel.... this is the answer I was looking for :)

"Nigel Armstrong" wrote:

> Hi Siu
> 
> If you had a document like this:
> 
> <Root>
>   <Child>A</Child
>   <Child>A</Child>
> </Root>
> 
> even though the name and content of the Child elements is the same, you can 
> use a positional predicate in your XPath expression to select each one in 
> turn: for example /Root/Child[1] and /Root/Child[2]. Will that approach not 
> work for your documents?
> 
> HTH
> 
> Nigel Armstrong
> 
> "Siu" wrote:
> 
> > Hi,
> > I've loaded an XmlDocument from a file XML: this file has many similar 
> > XmlNode and it is difficult to select them by using SelectSingleNode of the 
> > object XmlDocument.
> > 
> > I've this question: is it possible to identify each XmlNode of the 
> > XmlDocument by using an inner key or something like that ?
> > I precise that I 'm not allowed to change the file XML, therefore I can't 
> > add any key element or attribute in each node.
> > 
> > Thank in advance
0
SIU (13)
11/25/2004 8:37:03 AM
Reply:

Similar Artilces:

XMLWriter and XMLDocument
Okay I am using an XMLDocument object to process several thousands of lodgements (from a database) I am trying to output it from an XML Document to a file using the XmlDocument.WriteTo() method with an XmlWriter. It writes 131kB and then cuts out halfway through an element Is this a limitation of XmlDocument.WriteTo() ? What would be a better way to output it Thanks Ensure you're calling XmlWriter.Close() to cause the buffered writes to be flushed to the underlying stream/textwriter. -- Daniel Cazzulino [MVP XML] Clarius Consulting SA http://weblogs.asp.net/cazzu http://aspnet2.com ...

XmlDocument with URL
My goal is to load an xml document from a remote url, make some changes to it, and then display it in a webpage. Say my codebehind looks like this private void Page_Load(Object sender, EventArgs e) { XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, Encoding.UTF8); XmlDocument doc = new XmlDocument(); doc.Load(http://somexmlgeneratedhere.com?id=333); //manipulate the doc here doc.WriteTo(writer); } Im not getting the full document from the URL, I'm sure Im doing this wrong. Can anyone point me in the right direction? thanks in advance Dave He...

Internal problem on XmlDocument.Load( )
I have this really frustrating problem when calling XmlDocument.Load(string filename). Whenever I call this method in a web application in my Windows XP development PC, I get the following error: Specified argument was out of the range of valid values. Parameter name: The specified value must be greater than 0. Here's the stack trace: ------------------------- [ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: The specified value must be greater than 0.] System.Net.ServicePoint.set_ConnectionLimit(Int32 value) +60 System.Xml.XmlDo...

XSLT transform XmlDocument to XmlDocument?
I just want to make a transformation on the fly, without having to save the XML document to a file before or after the transformation. I don't find any examples of this. I see that the XslTranform.Transform() method can return an XmlReader, but how can that reader be converted to an XmlDocument object? Big thanks, Gustaf Gustaf Liljegren wrote: > I just want to make a transformation on the fly, without having to save > the XML document to a file before or after the transformation. I don't > find any examples of this. See <http://groups-beta.google.com/group/mic...

XmlNode -> Schema -> Object
Lets say I have an XmlNode that validates against some schema. I also have a class that was generated by the xsd tool using said schema. What is the best way to get from an XmlNode to an instance of the class? System.Xml.Serialization.XmlSerializer.Deserialize() accepts an XmlReader. http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemXmlSerializationXmlSerializerClassDeserializeTopic3.asp and you can create a System.Xml.XmlNodeReader from a System.Xml.XmlNode http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemXmlXmlNodeReaderClassctorTopic.asp "Brad Quinn&quo...

Loading XmlDocument with a file on network?
Can you load an XmlDocument with a file located on a network share? I thought maybe the XmlResolver could be used XmlUrlResolver resolver = new XmlUrlResolver() resolver.Credentials = CredentialCache.DefaultCredentials // Create and load the XmlDocument XmlDocument doc = new XmlDocument() doc.XmlResolver = resolver; // Set the resolver doc.Load(@"\\devsrv\profiles\0004.xml") OR.. doc.Load("//devsrv/profiles/0004.xml") But I get: "Logon failure: unknown user name or bad password" The problem is probably that the account that your application is running under...

XPathDocument to xmldocument
How to create XPathDocument object from xmldocument object thanks vikram wrote: > How to create XPathDocument object from xmldocument object First, be aware that such converting means copying the whole set of data in the XML document. Second, it's easy: XPathDocument doc = new XPathDocument(new XmlNodeReader(xmlDoc)); -- Oleg Tkachenko [XML MVP, MCP] http://blog.tkachenko.com ...

removing nodes from xmldocument
Here is an xml structure. i want to remove <a> nodes that do not have any child. How can i do that in csharp? <root> <a> <b/> </a> <a/> <a/> <a> <c/> </a> </root> i tried following but it does not work: xmlNodeList l = xr.getElementsByTagName("a"); foreach(XmlNode n in l) { if(n.HasChildNodes == false) xr.RemoveChild(n) } emid, Try this call this function inside the code; void RecurssionRemoval() { XmlNodeList l = xr.GetElementsByTagName("a"); ...

.NET XMLDocument Save issue
Hi, Currently we are using the .NET XMLDocument Class to manipulate some xml documents. The issue we are having is that when we save the XML files using the classes save method, empty xml tags will be saved with a CRLF instead of the empty value. This can be solved by setting the PreserveWhiteSpace property to true. But then the indentation is lost. E.g.:- Before Saving this is how the tags are. <Test></Test> After saving <Test> </Test> Has anybody come across this, is there any solution for this. Thanks Amendra. ...

XMLDocument <- Synchronization Trasformation Schema -> XMLDocument ?
I'm new to .NET XML classes, so here my dilemma I really like the XMLDataDocument concept of synchronizing automatically XMLDocument and DataSet with a common schema. Can I automatically syncronize 2 XMLDocument with Synchronization Trasformation Schema in the middle? Here my plan I'm going to write an application which the core data model is based on XMLDataDocument with my own schema. The application frontend will edit the XMLDataDocument core. The application will have to edit files with a well known XML document schema similar to my core. I can easily create an XSLT to tranform t...

Opening and altering XML-doc using XmlDocument wrecks havoc on doc
Hi I am trying to post-process some XML-documents from some third-party software. I open them, find the right element, manipulate the text and write it back to the element. Dim x As New Xml.XmlDocument Dim nl As Xml.XmlNodeList Dim text As String Dim textOutput As String x.Load(filename) nl = x.GetElementsByTagName("text") [snip, some manipulation of the text, not important...] nl.Item(0).InnerText = "<![CDATA[ " & textOutput & " ]]>" 'nl.Item(0).InnerText = textOutput x.Save("C:\Temp\XmlYt.xml") Now, the data I write ...

XmlDocument
Hi Oleg and All, Is this correct? Can I do this? <code> XmlDocument doc=new XmlDocument(); XPathNavigator nav = doc.CreateNavigator(); //Load the xml file. Change path if needed doc.Load(@"..\..\..\books.xml"); XslTransform xslt = new XslTransform(); xslt.Load(@"D:\XML\XSL Ex2\Personnel2.xsl"); StringWriter fs = new StringWriter(); xslt.Transform(doc, null, fs, null); XmlNode node=doc.SelectSingleNode("bookstore"); <- Here is the problem </code> I need to transform the XML First using xslt.transform then tak...

Create an XmlDocument from XmlSerializer?
Hello, This is probably a very simple question. I played around with it some = but couldn't get it. I'm got a custom class I'm serializing, I'm loading the results into a = new XmlDocument. What is the best way to take the results from the = XmlSerializer and convert it into an XmlDocument. I'm guessing the best = way to accomplish this is through streams. Can someone point me in the right direction as to the best way to do = this? I can serialize the class to a file, then load the file, but that = is like going around my elbow to get to my thumb!, there has to be a ...

Can an XmlNode from one XmlDocument be copied to another XmlDocument?
I'm wondering if one node that belongs to one XmlDocument can be appended to another XmlDocument as a new child without having to build a new node from scratch. I would think XmlNode.Clone() is for this purpose but no, it doesn't work. I got the following error: The node to be inserted is from a different document context Does anyone know if this is doable without building a new node and without putting through XSL? you have to build a new node and create your own copy function. if performance is not the top issue, use the InnerXml/OuterXml properties to copy. -- bruce (sqlwork...

XMLDocument <- Synchronization Trasformation Schema -> XMLDocument ? #2
I'm new to .NET XML classes, so here my dilemma: I really like the XMLDataDocument concept of synchronizing automatically XMLDocument and DataSet with a common schema. Can I automatically syncronize 2 XMLDocument with Synchronization Trasformation Schema in the middle? Here my plan. I'm going to write an application which the core data model is based on XMLDataDocument with my own schema. The application frontend will edit the XMLDataDocument core. The application will have to edit files with a well known XML document schema similar to my core. I can easily create an XSLT to tranfo...

XmlTextWriter,XmlDocument
Hi all, I need to embed an image to an existing xml file. I guess this is possible using XmlTextWriter.WriteBase64() method. My problem is that XmlTextWriter writes to a new document. How can I edit an existing doc (for example with XmlDocument class) and write an image to it? I'm sorry but I'm a bit confused about the difference between XmlTextWriter and XmlTextDocument. Thanks. Ars Comm - Ciro Ferraiuolo wrote: > Hi all, I need to embed an image to an existing xml file. I guess this is > possible using XmlTextWriter.WriteBase64() method. My problem is that > XmlTextWrit...

XmlDocument #2
Hi, I am using the XmlDocument class in my program. I fount there are no methods like GetAttributesByName or GetTagsByName, so I had to write my own (not very hard). I am a bit surprised that methods like (frequently needed) this do not exist. As I do not have much expirience I wonder if this is the case or I am just missing something. Thank you Please disregard it. I found what I was looking for "Z" wrote: > Hi, > > I am using the XmlDocument class in my program. > I fount there are no methods like GetAttributesByName or GetTagsByName, so I > had to write ...

Add XMLNodeList to new XMLDocument
All, I have a very large XML document that contains two types of elements. I want to select all the elements of each type and place them in separate XML documents. This is what I have so far: 'Add the Metis namespace so the querys will work lobj_namespaceManager = New XmlNamespaceManager(iobj_MetisModel.NameTable) lobj_namespaceManager.AddNamespace("Troux", "http://www.metis.no/metis") 'Execute the queries. iobj_Relationships = iobj_MetisModel.SelectNodes("//Troux:relationship", lobj_name...

Closing a file with XmlDocument?
I am storing some small amounts of data in an xml file using XmlDocument. I basically do a .Load(filename), processing, then .Save(filename). However, once and awhile on the .Load it will say the file is in use by another process. This is the only program to use that file. I am using C#. Any ideas on what is going on? "SirPoonga" <kevin.jonas@gmail.com> wrote in message news:1173208649.922129.8430@8g2000cwh.googlegroups.com... >I am storing some small amounts of data in an xml file using > XmlDocument. I basically do a .Load(filename), processing, > then .Save...

XMLREADER or XMLDocument???
How do I read the attributes of this XML? I have a page with text boxes that i want to read these values in. notice there are 2 Parameter tags with the same attributes. Code would help <TranslationRecords> <TranslationRecord TrxID="1"> <ParameterCollection> <Parameter KeyName="FielDelimiterChar" KeyValue="29" /> <Parameter KeyName="SegmentDelimiterChar" KeyValue="30" /> </ParameterCollection> </TranslationRecord> </TranslationRecords> Thanks Try this as a template. It should be gene...

Canonicalized XML from XmlDocument?
How can I obtain the C14N canonicalized format of an XML document subtree? Any help is greatly appreciated. I'm using the XmlDsigC14NTransform object to obtain the C14N canonicalized format. The output looks right, but I can't guarantee it... some xmlns attributes have been removed. An input document that I am validating indicates that it uses this transformation. Still, when I send the output of the transformation to the SHA1 hashing algorithm, ComputeHash yields a different DigestValue than the one on the input document. The input document is created using simple code for SignedX...

XmlDocument Trouble
Hi, I don't know why, but I can't seem to get this to work: Public Sub DoSomething() Dim sb as New StringBuilder() sb.Append("http://webservices.amazon.com/onca/xml?") sb.Append("Service=AWSECommerceService&SubscriptionId") sb.Append("=0525E2PQ81DD7ZTWTK82&Operation=ItemSearch") sb.Append("&SearchIndex=Books&Keywords=css") sb.Append("&ResponseGroup=ItemAttributes,Offers") Dim tr as New XmlTextReader(sb.ToString()) tr.Read() Dim xDoc as XmlDocument = New XmlDocument() xDoc.Load(tr) tr.Close() ...

How to ignore namespace in XMLDocument
Hi, I have this XML file that I need to parse. <property> <name>some name</name> <value>some value</value> </property> <report xmlns="http://schemas.site.com/test/test/"> <reportElementList> <reportElement> .... .... </reportElement> </reportElementList> My application works fine when I use doc.SelectNodes for 'property'. However, for 'report' it fails because of the xmlns=.... Is there a way to instruct the XMLDocument to ignore namespaces? BTW, I hav...

XmlDocument question
Hi, I'd like to implement the following feature, but I don't know how: When I read in a document with 'empty' elements, i'd like them to be 'compressed'. e.g.: .... doc.LoadXml("<item><name></name></item>"); doc.Save(textWriter); .... returns "<item><name></name></item>" Is there a way to make it return "<item><name /></item>"? (or some other way, without XmlDocument?) "Brecht Yperman" <BrechtYperman@discussions.microsoft.com> wrote in message news:F...

XmlDocument not being written to
Hi Everyone, I am using the following code to write out an XmlDocument that I have. I create an XmlTextWriter and try to save / flush it. Earlier, I had created an XmlElement (using xmlDoc.createElemenet("name') ) However, the xml file size is always 0. WHat could I be missing? private void writeXMLFile() { XmlTextWriter x = new XmlTextWriter(XmlFileName, null); xmlDoc.Save(x); x.Flush(); x.Close(); return; } Thanks. On May 1, 3:54 pm, C Sharp <a.kamr...@gmail.com> wrote: > Hi Everyone, ...