I am totally new to this and I need to create this xml document for my orginization. For sure I am aware that I should use Domdocument, but I cant figure out all methods and what they are doing.   What I dont understand is how to apply the first tag after the xml tag - what method in PHP should I use for that?  Can someone point me in the right direction so that my XML document looks like this?  &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;Persons PageCount="1" PageIndex="1" ApplicationId="[ApplicationGuid]" xmlSchemaVersion="1.0" GenerationDate="2013-11-25T18:15:36" IsIncremental="true"&gt; &lt;!-- Add member --&gt; &lt;Person CreateDate="2008-08-29T08:39:44" LMDate="2014-03-14T10:47:22" OptionType="Update"&gt;     &lt;PersonId&gt;82&lt;/PersonId&gt;     &lt;PersonalNumber&gt;19471204-6310&lt;/PersonalNumber&gt;     &lt;FirstName&gt;Peter&lt;/FirstName&gt;     &lt;LastName&gt;Peterson&lt;/LastName&gt;     &lt;BirthDate&gt;1947-12-04&lt;/BirthDate&gt;     &lt;Gender&gt;male&lt;/Gender&gt;     &lt;Organisations&gt;     &lt;Organisation OptionType="Update"&gt;     &lt;OrgID&gt;31215&lt;/OrgID&gt;     &lt;OrganisationRF_NR&gt;45264&lt;/OrganisationRF_NR&gt;      &lt;OrganisationNumber&gt;802421-7948&lt;/OrganisationNumber&gt;      &lt;Sports&gt;        &lt;Sport OptionType="Update"&gt;          &lt;SportID&gt;43&lt;/SportID&gt;          &lt;IsActive LMDate="2011-11-17T15:31:06"&gt;true&lt;/IsActive&gt;        &lt;/Sport&gt;     &lt;/Sports&gt;   &lt;/Organisation&gt;   &lt;/Organisations&gt; &lt;/Person&gt; &lt;/Persons&gt;   Best regards, Joakim
5364
Is it possible to use PHP's SimpleXML functions to create an XML object from scratch?  Looking through the function list, there's ways to import an existing XML string into an object that you can then manipulate, but if I just want to generate an XML object programmatically from scratch, what's the best way to do that?  I figured out that you can use simplexml_load_string() and pass in the root string that you want, and then you've got an object you can manipulate by adding children... although this seems like kind of a hack, since I have to actually hardcode some XML into the string before it can be loaded.  I've done it using the , although it's a little confusing because I'm not sure what the DOM has to do with creating a pure XML document... so maybe it's just badly named :-)
13314
I'm looking for a way to insert a &lt;style&gt; tag into an HTML page with JavaScript.  The best way I found so far:  var divNode = document.createElement("div"); divNode.innerHTML = "&lt;br&gt;&lt;style&gt;h1 { background: red; }&lt;/style&gt;"; document.body.appendChild(divNode);   This works in Firefox, Opera and Internet Explorer but not in Google Chrome. Also it's a bit ugly with the &lt;br&gt; in front for IE.  Does anyone know of a way to create a &lt;style&gt; tag that   Is nicer Works with Chrome?   Or maybe   This is a non-standard thing I should avoid Three working browsers are great and who uses Chrome anyway?
54857
I want to generate the html elements and their classes to fit my styling of the main menu.    I'm confused by all the near-possibilities offered in the api documentation and by looking at core themes etc. and still can't quite see what I have to do, or where I have to do it. I would be very grateful for clear pointers to:     which php functions I have to write;  which variables I need to add / update;  in which files the functions will go.   Presumably, in MYTHEME.theme I will need a preprocess function of some sort to add to the attributes and item.attributes variables that links.html.twig uses to print the menu ul and the menu item li's.   [Update] So far I have discovered one way to place classes on the Main Menu's ul but ideally I would like to add a class to each submenu's ul indicating the depth of the sub-menu. And I cannot locate any documentation or examples from which I can understand the generation / modifying of the main menu's individual link items.    This function goes into the file  MYTHEME.theme.  function MYTHEME_preprocess_page(&amp;$variables) {    // Pass the main menu and secondary menu to the template as render arrays.   if (!empty($variables['main_menu'])) {     $variables['main_menu']['#attributes']['id'] = 'main-menu-links';     $variables['main_menu']['#attributes']['class'] = array('links', 'clearfix', 'MYNEW_class');   }  }
92375
Here's an example I just ran into. I'm trying to put some HTML in the label of my field.  $form['field_feedback']['und']['#title'] &lt;- has the title $form['field_feedback']['und'][0]['#title'] &lt;- has the title $form['field_feedback']['und'][0]['value']['#title'] &lt;- has the title. (Works)   Why are there three populated #title attributes with only one being used?
112079
I need to convert HTML documents into valid XML, preferably XHTML. What's the best way to do this? Does anybody know a toolkit/library/sample/...whatever that helps me to get that task done?  To be a bit more clear here, my application has to do the conversion automatically at runtime. I don't look for a tool that helps me to move some pages to XHTML manually.
36382
I need to create an XML schema that validates a tree structure of an XML document. I don't know exactly the occurrences or depth level of the tree.  XML example:  &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;node&gt;   &lt;attribute/&gt;   &lt;node&gt;     &lt;attribute/&gt;     &lt;node/&gt;         &lt;/node&gt; &lt;/node&gt;    Which is the best way to validate it?  Recursion?
4477
Let's say I have some XML like this  &lt;channel&gt;   &lt;item&gt;     &lt;title&gt;This is title 1&lt;/title&gt;   &lt;/item&gt; &lt;/channel&gt;   The code below does what I want in that it outputs the title as a string  $xml = simplexml_load_string($xmlstring); echo $xml-&gt;channel-&gt;item-&gt;title;   Here's my problem.  The code below doesn't treat the title as a string in that context so I end up with a SimpleXML object in the array instead of a string.  $foo = array( $xml-&gt;channel-&gt;item-&gt;title );   I've been working around it like this  $foo = array( sprintf("%s",$xml-&gt;channel-&gt;item-&gt;title) );   but that seems ugly.  What's the best way to force a SimpleXML object to a string, regardless of context?
121031
I have a the following code:  // Create an Entity with wrapper   $node = entity_create('node', array('type' =&gt; 'person'));   $entity = entity_metadata_wrapper('node',  $node);    // Add a node title   $entity-&gt;title = $person['name'];    // Add the address information   $entity-&gt;field_person_address-&gt;thoroughfare = $person['address'];   $entity-&gt;field_person_address-&gt;locality = $person['city'];   $entity-&gt;field_person_address-&gt;administrative_area = $person['state'];   $entity-&gt;field_person_address-&gt;postal_code = $person['postalcode'];   $entity-&gt;field_person_address-&gt;country = $person['country'];    // Save the entity   $entity-&gt;save();   The data is saved in the DB perfeclty, but I need to get the entity ID of the new save node.   How do I do that?
4559
How to create a node by programatically submitting the existing node add form, and most importantly using it's validation process instead of re-implementing all of the property/field validation logic so we piggyback off of the existing code.
47711
I am testing against the following test document:  &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"                        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;    &lt;head&gt;         &lt;title&gt;hi there&lt;/title&gt;     &lt;/head&gt;     &lt;body&gt;         &lt;img class="foo" src="bar.png"/&gt;     &lt;/body&gt; &lt;/html&gt;   If I parse the document using lxml.html, I can get the IMG with an xpath just fine:  &gt;&gt;&gt; root = lxml.html.fromstring(doc) &gt;&gt;&gt; root.xpath("//img") [&lt;Element img at 1879e30&gt;]   However, if I parse the document as XML and try to get the IMG tag, I get an empty result:  &gt;&gt;&gt; tree = etree.parse(StringIO(doc)) &gt;&gt;&gt; tree.getroot().xpath("//img") []   I can navigate to the element directly:  &gt;&gt;&gt; tree.getroot().getchildren()[1].getchildren()[0] &lt;Element {http://www.w3.org/1999/xhtml}img at f56810&gt;   But of course that doesn't help me process arbitrary documents.  I would also expect to be able to query etree to get an xpath expression that will directly identify this element, which, technically I can do:  &gt;&gt;&gt; tree.getpath(tree.getroot().getchildren()[1].getchildren()[0]) '/*/*[2]/*' &gt;&gt;&gt; tree.getroot().xpath('/*/*[2]/*') [&lt;Element {http://www.w3.org/1999/xhtml}img at fa1750&gt;]   But that xpath is, again, obviously not useful for parsing arbitrary documents.  Obviously I am missing some key issue here, but I don't know what it is.  My best guess is that it has something to do with namespaces but the only namespace defined is the default and I don't know what else I might need to consider in regards to namespaces.  So, what am I missing?
28523
Here's a PHP example of mine. Can anyone find a shorter/easier way to do this?  &lt;? foreach($posts as $post){?&gt;     &lt;div class="&lt;?=($c++%2==1)?‘odd’:NULL?&gt;"&gt;         &lt;?=$post?&gt;     &lt;/div&gt; &lt;? }?&gt;  &lt;style&gt;     .odd{background-color:red;} &lt;/style&gt;   Examples in other languages would be fun to see as well.
105831
Drupal 7. Custom module. I have a content type 'RFI' with a handful of fields I created with Drupal UI. I want a user to: fill out a form &amp; click submit while drupal: saves fields to database, creates a new node of 'RFI' and populates the fields of the node with the content provided by the form's corresponding fields.  From what I understand:  Build a form with fields (taking from the 'DBTNG examples' module just for clarity):  function rfi_build_form($form, &amp;$form_state) { $form = array();  $form['add'] = array( '#type'  =&gt; 'fieldset', '#title' =&gt; t('Add a person entry'), ); $form['add']['name'] = array( '#type'  =&gt; 'textfield', '#title' =&gt; t('Name'), '#size'  =&gt; 15, ); $form['add']['surname'] = array( '#type'  =&gt; 'textfield', '#title' =&gt; t('Surname'), '#size'  =&gt; 15, ); $form['add']['age'] = array( '#type'  =&gt; 'textfield', '#title' =&gt; t('Age'), '#size'  =&gt; 5, '#description' =&gt; t("Values greater than 127 will cause an exception. Try it - it's a    great example why exception handling is needed with DTBNG."), ); $form['add']['submit'] = array( '#type'  =&gt; 'submit', '#value' =&gt; t('Add'), ); return $form; }   Here the form fields are saved to database with database API.  function rfi_build_submit($form, &amp;$form_state) { global $user;  // Save the submitted entry. $entry = array( 'name'    =&gt; $form_state['values']['name'], 'surname' =&gt; $form_state['values']['surname'], 'age'     =&gt; $form_state['values']['age'], 'uid'     =&gt; $user-&gt;uid, ); $return = dbtng_example_entry_insert($entry); if ($return) { drupal_set_message(t("Created entry @entry", array('@entry' =&gt; print_r($entry, TRUE)))); } }   Now here is how I know how to create a node of RFI type. How do I take the values of the fields above [name], [surname], [age] and have them related to corresponding fields in my content type?  function rfi_build_type($form, &amp;$form_state){ $node = new stdClass(); $node-&gt;type = 'rfi'; $node-&gt;name = ''; $node-&gt;surname = ''; $node-&gt;age = ''; $node-&gt;language = 'en'; $node-&gt;uid = 1; node_save($node); }   I was thinking that since the fields have been saved already, that I could use a database query to get these values, but intuition tells me I'm overlooking something.  Thank you!
87922
I used the Bing webmaster tool's SEO analyzer on my website, and it reported:     There are multiple  tags on the page.   It recommends that there should only be one &lt;h1&gt; tag on the page.  The page is a listing of blog posts for a category. So each blog entry is structured like this.  &lt;article&gt;     &lt;header&gt;&lt;h1&gt;&lt;a&gt;...&lt;/a&gt;&lt;/h1&gt;&lt;/header&gt;     &lt;p&gt;summary...&lt;/p&gt; &lt;/article&gt; &lt;article&gt;     &lt;header&gt;&lt;h1&gt;&lt;a&gt;...&lt;/a&gt;&lt;/h1&gt;&lt;/header&gt;     &lt;p&gt;summary...&lt;/p&gt; &lt;/article&gt; &lt;article&gt;     &lt;header&gt;&lt;h1&gt;&lt;a&gt;...&lt;/a&gt;&lt;/h1&gt;&lt;/header&gt;     &lt;p&gt;summary...&lt;/p&gt; &lt;/article&gt; &lt;article&gt;     &lt;header&gt;&lt;h1&gt;&lt;a&gt;...&lt;/a&gt;&lt;/h1&gt;&lt;/header&gt;     &lt;p&gt;summary...&lt;/p&gt; &lt;/article&gt;   How is this invalid? I thought this was the correct way to describe a post in HTML5.
76092
I need to add PHP tags surrounding a file. It's easy to append them using  find . -exec echo "?&gt;" &gt;&gt; '{}' \;   but how can I prepend the tag &lt;?php?
45764
I have a directory full of XML files that look like this, for which I want to change the value of the "offset" element number from 1 to some other number  $ cat my.xml       &lt;offset xmlns=""&gt;1&lt;/offset&gt;   I wrote various combinations of this sed command, but nothing I tried runs without an error.  I am pretty sure that I need to escape some of the characters, but those that I've tried always end in errors ("unexpected token", "unknown option", etc).  I also tried without the -e flag, since it really isn't an expression.  sed -i -e s/&lt;offset xmlns=""&gt;1&lt;/offset&gt;/&lt;offset xmlns=""&gt;99&lt;/offset&gt;/ *.xml   Any help would be appreciated.
21088
i'm trying to create a multilingual node using a php script.  I'm doing this:   $node = new stdClass();  $node-&gt;title = "Test ".mktime();  $node-&gt;type = "job";  $node-&gt;language = 'de'; // Or e.g. 'en' if locale is enabled  $node-&gt;uid = $user-&gt;uid;   $node-&gt;status = 1; //(1 or 0): published or not  $node-&gt;promote = 0; //(1 or 0): promoted to front page  $node-&gt;comment = 1; //2 = comments on, 1 = comments off  $node-&gt;path = array('alias' =&gt; 'das-ist-ein-test-'.mktime());  $node-&gt;body[$node-&gt;language][0]['value']   = "Body Body Body";  $node-&gt;body[$node-&gt;language] = text_summary("Body Body Body");  $node-&gt;body[$node-&gt;language]  = 'filtered_html';  node_save($node);   As long as i set $node->language to 'und' everything is working fine. But as soon as I set the language to 'de' or 'en' (both languages are activated in my Drupal installation) the body text doesn't get saved.  So my question is: can anybody provide me with a working example of how to store a multlingual node (de,en) into Drupal using program code.  Thank you
11435
I want to know how to create a new tag on Stack Overflow. Where is the entrance of this function?   Please post a screenshot for me. Thanks a lot.