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>
...
..
my C# code is:
XElement hen = XElement.Load(@"Henv-eks1-v1.0.xml");
XElement test = hen.Element("Patient");
Console.WriteLine(test.value);
says that test is null, what i'm i doing wrong??

Signature
Projectleader / .NET system devloper
Martin Honnen - 07 Mar 2008 15:16 GMT
> hi,
>
[quoted text clipped - 39 lines]
>
> says that test is null, what i'm i doing wrong??
Well first of all all elements are in the default namespace
http://www.kith.no/xmlstds/henvisning/2005-07-08 so you need
XNamespace hv = "http://www.kith.no/xmlstds/henvisning/2005-07-08";
and then you need to qualify names e.g.
hv + "Patient"
that you use in your code.
Additionally the Patient element is not a child of the root element but
rather of the ServReq element so you might try e.g.
hen.Element(hv + "ServReq").Element(hv + "Patient")

Signature
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Benn H.J. Molund - 10 Mar 2008 10:16 GMT
Thx, helpet me alot:-)
Is ther a way that i can get onlye the xml tree without using the namspace?
Once again thanks for help:-)

Signature
Projectleader / .NET system devloper
> > hi,
> >
[quoted text clipped - 49 lines]
> rather of the ServReq element so you might try e.g.
> hen.Element(hv + "ServReq").Element(hv + "Patient")
Martin Honnen - 10 Mar 2008 13:00 GMT
> Is ther a way that i can get onlye the xml tree without using the namspace?
I am not sure I understand what you want to achieve. Can you explain
"which xml tree" you are looking for?

Signature
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Benn H.J. Molund - 10 Mar 2008 13:18 GMT
Sorry, I ment all data(Elements and atributes) in the Patient part of the xml.
I asume you must ref to each element with the namespace atribute?

Signature
Projectleader / .NET system devloper
> > Is ther a way that i can get onlye the xml tree without using the namspace?
>
> I am not sure I understand what you want to achieve. Can you explain
> "which xml tree" you are looking for?
Martin Honnen - 10 Mar 2008 13:31 GMT
> Sorry, I ment all data(Elements and atributes) in the Patient part of the xml.
> I asume you must ref to each element with the namespace atribute?
Using the XNamespace is straight forward and simple.
Ignoring namespaces is possible but not very helpful in my view. If you
really want to do that:
XElement message = XElement.Load(@"..\..\XMLFile1.xml");
XElement patient = message.Elements().Where(el =>
el.Name.LocalName == "ServReq").Elements().Where(el => el.Name.LocalName
== "Patient").First();
if (patient != null)
{
Console.WriteLine(patient);
}
else
{
Console.WriteLine("Not found.");
}

Signature
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Benn H.J. Molund - 10 Mar 2008 14:02 GMT
aha, this was the mind opner for me :-) thx

Signature
Projectleader / .NET system devloper
> > Sorry, I ment all data(Elements and atributes) in the Patient part of the xml.
> > I asume you must ref to each element with the namespace atribute?
[quoted text clipped - 15 lines]
> Console.WriteLine("Not found.");
> }