473,799 Members | 3,270 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML ID attribute & GetElementById

>Is it actually valid to have an XML document with 2 XML Elements having the
same ID attribute? XML Spy seems to allow something like the following
<?xml version="1.0" encoding="UTF-8"?>
<FormDefiniti on xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespace SchemaLocation= "Forms.xsd" >
<list id="1">
<status>partial ly completed</status>
</list>
<list id="1">
<status>complet ed</status>
</list>
</FormDefinition>

If it is valid, how can I utilise System.Xml.XmlD ocument.GetElem entById
method() (which returns 1 XmlNode)?
Nov 12 '05 #1
3 8744
With the following XSD:
<!---------------------------Start of Form.xsd--------------------------->
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefa ult="qualified" attributeFormDe fault="unqualif ied">
<xs:element name="FormDefin ition">
<xs:complexType >
<xs:sequence>
<xs:element name="FormName" minOccurs="0">
<xs:complexType >
<xs:simpleConte nt>
<xs:extension base="xs:string ">
<xs:attribute name="id" type="xs:ID" use="required"/>
</xs:extension>
</xs:simpleConten t>
</xs:complexType>

</xs:element>
<xs:element name="FormTitle " minOccurs="0">
<xs:complexType >
<xs:simpleConte nt>
<xs:extension base="xs:string ">
<xs:attribute name="ReadFromD B" type="xs:boolea n" use="required"/>
<xs:attribute name="id" type="xs:ID" use="required"/>
</xs:extension>
</xs:simpleConten t>
</xs:complexType>
</xs:element>
</xs:schema>
<!---------------------------End of Form.xsd--------------------------->

And the following XML Document
<!---------------------------Start of Test.xml--------------------------->
<?xml version="1.0" encoding="UTF-8"?>
<FormDefiniti on xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespace SchemaLocation= "Form.xsd">
<FormName id="a1">test form </FormName>
<FormTitle ReadFromDB="tru e" id="a2">Island </FormTitle>
</FormDefinition>
<!---------------------------End of Test.xml--------------------------->

xmlDoc1.GetElem entById("a1") is returning null. How can i fix this? Can I
have an xs:ID that contains numbers only? Is there a method to search for a
node given an id attribute instead?

"Patrick" wrote:
Is it actually valid to have an XML document with 2 XML Elements having the

same ID attribute? XML Spy seems to allow something like the following
<?xml version="1.0" encoding="UTF-8"?>
<FormDefiniti on xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespace SchemaLocation= "Forms.xsd" >
<list id="1">
<status>partial ly completed</status>
</list>
<list id="1">
<status>complet ed</status>
</list>
</FormDefinition>

If it is valid, how can I utilise System.Xml.XmlD ocument.GetElem entById
method() (which returns 1 XmlNode)?

Nov 12 '05 #2
Currently XmlDocument.Get ElementById() works only
with the ids specified through a DTD. The XSD info is
ignored for this scenario. If you know the schema ahead
of time you might want to simply use SelectNodes() a la:
XmlDocument.Sel ectNodes("//FormName[@id='a1']")

Ion

"Patrick" <qu*******@news group.nospam> wrote in message
news:6E******** *************** ***********@mic rosoft.com...
With the following XSD:
<!---------------------------Start of Form.xsd--------------------------->
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefa ult="qualified" attributeFormDe fault="unqualif ied">
<xs:element name="FormDefin ition">
<xs:complexType >
<xs:sequence>
<xs:element name="FormName" minOccurs="0">
<xs:complexType >
<xs:simpleConte nt>
<xs:extension base="xs:string ">
<xs:attribute name="id" type="xs:ID" use="required"/>
</xs:extension>
</xs:simpleConten t>
</xs:complexType>

</xs:element>
<xs:element name="FormTitle " minOccurs="0">
<xs:complexType >
<xs:simpleConte nt>
<xs:extension base="xs:string ">
<xs:attribute name="ReadFromD B" type="xs:boolea n" use="required"/>
<xs:attribute name="id" type="xs:ID" use="required"/>
</xs:extension>
</xs:simpleConten t>
</xs:complexType>
</xs:element>
</xs:schema>
<!---------------------------End of Form.xsd--------------------------->

And the following XML Document
<!---------------------------Start of Test.xml--------------------------->
<?xml version="1.0" encoding="UTF-8"?>
<FormDefiniti on xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespace SchemaLocation= "Form.xsd">
<FormName id="a1">test form </FormName>
<FormTitle ReadFromDB="tru e" id="a2">Island </FormTitle>
</FormDefinition>
<!---------------------------End of Test.xml--------------------------->

xmlDoc1.GetElem entById("a1") is returning null. How can i fix this? Can I have an xs:ID that contains numbers only? Is there a method to search for a node given an id attribute instead?

"Patrick" wrote:
Is it actually valid to have an XML document with 2 XML Elements having
the same ID attribute? XML Spy seems to allow something like the following
<?xml version="1.0" encoding="UTF-8"?>
<FormDefiniti on xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespace SchemaLocation= "Forms.xsd" >
<list id="1">
<status>partial ly completed</status>
</list>
<list id="1">
<status>complet ed</status>
</list>
</FormDefinition>

If it is valid, how can I utilise System.Xml.XmlD ocument.GetElem entById
method() (which returns 1 XmlNode)?

Nov 12 '05 #3
Patrick wrote:
Can I
have an xs:ID that contains numbers only?
Not, in XML ID cannot be numbers only.
Is there a method to search for a
node given an id attribute instead?


Sure. Use XPath:

xmlDoc.SelectNo des("//*[@id='1']");

--
Oleg Tkachenko [XML MVP, MCAD]
http://blog.tkachenko.com
Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
9476
by: Sammy | last post by:
Hi, my mind is going crazy. I have tried everything I can think of to no avail. I have tried Disable Output Escaping. I tried to think of a way of enclosing the attribute data in a CDATA element. That did not parse. Here is my question: How can I get attribute values to not get converted from &apos; to '
2
2173
by: Adam | last post by:
I have a scrollbar that runs at the top of my page, I have it in a external js file and call it in the head tags of the webpage code. can you one tell me how to get this code to work with other browsers mainly Netscape 7 and above. Currently it doesn't display. this is the scroll bar code Thanks ----------------------------------------------------------------------
4
3230
by: johkar | last post by:
When the output method is set to xml, even though I have CDATA around my JavaScript, the operaters of && and < are converted to XML character entities which causes errors in my JavaScript. I know that I could externalize my JavaScript, but that will not be practical throughout this application. Is there any way to get around this issue? Xalan processor. Stripped down stylesheet below along with XHTML output. <?xml version='1.0'?>...
12
6329
by: ~~~ .NET Ed ~~~ | last post by:
Hi, I have a standalone XML file (with the appropriate xml document header) that works fine when I load it using XmlDocument. I can have child elements like this without problems: <SomeChildElement type="c" href="There.aspx?id=5" /> But as soon as I change it to something like this: <SomeChildElement type="c" href="There.aspx?id=5&amp;t=m" />
4
3729
by: tfortney | last post by:
I created an iframe HtmlGenericControl that has an ampersand in the "src" attribute..... Dim faxFrame As New HtmlGenericControl("iframe") faxFrame.Attributes.Add("width", "100%") faxFrame.Attributes.Add("height", "90%") faxFrame.Attributes.Add("frameborder", "no") faxFrame.Attributes.Add("src", "/archive/view.aspx?isPlugin=" & isPlugin & "&iDoc=" & Server.UrlEncode(intDoc))
2
13937
by: charles-brewster | last post by:
I'm trying to write a simple JavaScript function which will use a button to copy table cell data into a form input text box as the "value" attribute. The following is intended to test the function, but doesn't work. I'm new to this - previous JavaScript experience mostly copy & paste - could somebody please point to where I'm going wrong. ~~~~~~~~~~~~~~~~~~~~~~~~~ <head>
7
8457
chunk1978
by: chunk1978 | last post by:
can someone please tell me what is wrong with this function's syntax? it's not working for me... if (document.getElementById('DIVinvoicesubtotal').style.display = 'none' && document.getElementById('DIVgst').style.display = 'none' && document.getElementById('DIVqst').style.display = 'none' && document.getElementById('DIVhst').style.display = 'none';) { form.invoicesubtotal.value=""; form.gst.value=""; form.qst.value="";...
15
3958
by: Inny | last post by:
Hello, I found this simple js star rating script that I want to modify slightly. firstly I want to retain current vote , say 3 stars, untill its changed again. right now it resets to unvoted on refresh. I know you could use cookies but I also want to give it a unique identifier so that if i put it in my topic header templet, its unique to each topic (retaining whatever vote for each topic untill changed again) . perhaps this is not...
5
2173
by: elbin | last post by:
Hello, first to say that I am a total beginner in Javascript but I know some programming (python in particular) and am able to understand methods/parameters and so on. Here's my problem: I am trying to set up a page that changes every time it's visited, but without using php(which i don't know either) because it's not active on the server. The thing that should change is a single number in one attribute of an <embed> tag inside an <object>....
0
10490
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10259
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10238
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9077
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7570
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5589
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.