root-node

PHP5: Find Root Node in DOMDocument

試著忘記壹切 提交于 2019-11-29 09:28:00
I have a PHP5 DOMDocument and I try to find the root node (not the root element). Example: <test> <element> <bla1>x</bla1> <bla2>x</bla2> </element> <element> <bla1>y</bla1> <bla2>y</bla2> </element> <element> <bla1>z</bla1> <bla2>z</bla2> </element> </test> I want to get the DOMNode of "test" so that I can call - for example - hasChildNodes. I can get the "documentElement", but that's a DOMElement. Maybe I can go from there? $d = DOMDocument::loadXML($xml); // [... do some stuff here to find document's root node ...] if ($rootnode->hasChildNodes()) echo 'yayy!' Who can fill the gap? I seem to

C# Xml serialization, collection and root element

拥有回忆 提交于 2019-11-29 06:14:56
My app serializes objects in streams. Here is a sample of what I need : <links> <link href="/users" rel="users" /> <link href="/features" rel="features" /> </links> In this case, the object is a collection of 'links' object. -----------First version At first I used the DataContractSerializer , however you cannot serialize members as attributes ( source ) Here is the object : [DataContract(Name="link")] public class LinkV1 { [DataMember(Name="href")] public string Url { get; set; } [DataMember(Name="rel")] public string Relationship { get; set; } } And here is the result : <ArrayOflink xmlns:i=