Asking for XML atribute value
HI,
I m lost when I wanna ask for attributes value’s
XML file:
hi,
my xml file is:
<?xml version="1.0" encoding="ISO-8859-1"?>
<Message xmlns="http://www.kith.no/xmlstds/henvisning/2005-07-08"
xmlns:xsd="http://www.w3.org/2001/XMLSchema.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kith.no/xmlstds/henvisning/2005-07-08
Henvisning-v1.0.xsd">
<Type V="H"/>
<MsgVersion>v1.0 2005-07-08</MsgVersion>
<MIGversion>v1.0 2005-07-08</MIGversion>
<GenDate V="2005-07-06T11:30:47"/>
<MsgId>Referansenummer123456</MsgId>
<ServReq>
<!-- Opplysninger om henvisningen -->
<ServType V="N"/>
<IssueDate V="2002-09-14"/>
<MsgDescr V="1" DN="Utredning"/>
<Id>FY020725A</Id>
<Patient>
<!-- Opplysninger om pasient -->
<Sex V="1"/>
<DateOfBirth V="1940-09-16"/>
<Name>Syk, Petter</Name>
<OffId>16094034523</OffId>
<TypeOffId V="FNR"/>
<!-- Kliniske opplysninger - dekker Utredningsresultater, tidligere
sykdommer, Cave og legemidler -->
<!-- Utredningsresultater -->
<InfItem>
<Observation>
...
..
XElement xmlHenvisning = XElement.Load(@"Henv-eks1-v1.0.xml");
XNamespace nsHenvisning = xmlHenvisning.GetDefaultNamespace();
XElement patient = xmlHenvisning.Element(nsHenvisning +
"ServReq").Element(nsHenvisning + "Patient");
foreach(XAttribute a in patient.Attributes())
{
Console.WriteLine(a.Value);
}
Returns null, why?

Signature
Projectleader / .NET system devloper
Martin Honnen - 11 Mar 2008 16:10 GMT
> <Message xmlns="http://www.kith.no/xmlstds/henvisning/2005-07-08"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema.xsd"
[quoted text clipped - 13 lines]
> <Id>FY020725A</Id>
> <Patient>
^^^^^^^^^
That Patient element does not have any attributes, attributes would look
like this
<Patient att1="value 1" att2="value 2">

Signature
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/