I have an xml file of this structure  &lt;?xml version="1.0" encoding="iso-8859-1"?&gt; &lt;my_events&gt;                         &lt;event id="e20111129215359"&gt;                             &lt;title&gt;the title&lt;/title&gt;                             &lt;channel id="1"&gt;                                 &lt;name&gt;A name&lt;/name&gt;                                 &lt;onclick&gt;&lt;/onclick&gt;                             &lt;/channel&gt;                             &lt;event_site&gt;                                 &lt;name/&gt;                                 &lt;url/&gt;                             &lt;/event_site&gt;                             &lt;start_date&gt;Thu Mar 08 2012&lt;/start_date&gt;                             &lt;start_time&gt;11:00 AM&lt;/start_time&gt;                             &lt;end_date&gt;null&lt;/end_date&gt;                             &lt;end_time&gt;null&lt;/end_time&gt;                             &lt;notes&gt;Notes for the event&lt;/notes&gt;                         &lt;/event&gt;  &lt;/my_events&gt;   To delete an event, I have this php function.  &lt;?php  include_once("phpshared.php");  function delete_event( $nodeid ) {      $nodes = new SimpleXMLElement('my_events.xml', LIBXML_NOCDATA, true);      $node = $nodes-&gt;xpath("/my_events/event[@id='$nodeid']");      $node-&gt;parentNode-&gt;removeChild($node);      $formatted = formatXmlString($nodes-&gt;asXML());     $file = fopen ('my_events.xml', "w");      fwrite($file, $formatted);      fclose ($file);    }  echo delete_event(trim($_REQUEST['nodeid']));  ?&gt;   That doesn't delete the node.  Is there a different way to do this?
19672
I have several identical elements with different attributes that I'm accessing with SimpleXML:  &lt;data&gt;     &lt;seg id="A1"/&gt;     &lt;seg id="A5"/&gt;     &lt;seg id="A12"/&gt;     &lt;seg id="A29"/&gt;     &lt;seg id="A30"/&gt; &lt;/data&gt;   I need to remove a specific seg element, with an id of "A12", how can I do this?  I've tried looping through the seg elements and unsetting the specific one, but this doesn't work, the elements remain.  foreach($doc-&gt;seg as $seg) {     if($seg['id'] == 'A12')     {         unset($seg);     } }
120955
I am creating a lightweight editor in C# and would like to know the best method for converting a string into a nicely formatted XML string.  I would hope that there's a public method in the C# library like "public bool FormatAsXml(string text, out string formattedXmlText)", but it couldn't be that easy, could it?  Very specifically, what would the method "SomeMethod" have to be that would produce the output below?  string unformattedXml; string formattedXml;  unformattedXml = "&lt;?xml version=\"1.0\"?&gt;&lt;book&gt;&lt;author&gt;Lewis, C.S.&lt;/author&gt;&lt;title&gt;The Four Loves&lt;/title&gt;&lt;/book&gt;" formattedXml = SomeMethod(unformattedXml);  Console.WriteLine(formattedXml);   Output:  &lt;?xml version="1.0"?&gt;   &lt;book id="123"&gt;     &lt;author&gt;Lewis, C.S.&lt;/author&gt;     &lt;title&gt;The Four Loves&lt;/title&gt;   &lt;/book&gt;
83825
How does one remove a field from a node programmatically? I have a migration in hook_update_N that moves the contents from a a field into a custom table. After that migration, I want to remove the field in that same function.  Are there any field API's that cater removing fields?  Edit, Solution: Because the answers lack actual code, here is what I did to move fields from the $users into my own records and subsequently remove the field from the database;  function my_module_update_7005(&amp;$sandbox) {   $slice = 100;   //Fetch users from database;   if (!isset($sandbox['progress'])) {     $sandbox['progress'] = 0;     $sandbox['current_uid'] = 0;     // We'll -1 to disregard the uid 0...     $sandbox['max'] = db_query('SELECT COUNT(DISTINCT uid) FROM {users}')-&gt;fetchField() - 1;   }   if (empty($users)) {     $sandbox["current_uid"] += $slice;   }   $users = db_select('users', 'u')     -&gt;fields('u', array('uid', 'name'))     -&gt;condition('uid', $sandbox['current_uid'], '&gt;')     -&gt;range(0, $slice)     -&gt;orderBy('uid', 'ASC')     -&gt;execute();   //Loop trough users;   foreach ($users as $user) {     $foo = new Foo();     // Warning: drupal's fields return mixed values; e.g. NULL versus an int.     $foo-&gt;debits = (int) $user-&gt;user()-&gt;field_credits["und"][0]["value"];     $foo-&gt;save();      $sandbox['progress']++;     $sandbox['current_uid'] = $user-&gt;uid;   }    $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);    // Remove the field.   field_delete_field("field_credits"); //note that the name for Foo is field_foo   field_purge_batch($sandbox['max']+1);//Drupal seems to have an offbyone problem. }
17427
I'm porting a module that currently works with Blocks/BlockForms to Paragraphs/NodeForms. I'm inserting an embedded form inside a Paragraph inside a Node Edit page using a hook_field_widget_entity_reference_paragraphs_form_alter. The general structure where the form gets inserted is: $form['field']['widget'][0]['settings'][form here]  After this the form displays as expected on the node edit page. The inserted form goes through a number of #process steps. The element in question is a select form that when the button underneath it is pressed, is supposed to retrieve some data via a custom submit handler and place it on the page with ajax:  The array for this element looks like this:  You can see the custom submit handler that is supposed to fire when 'Select Segment Set' is pressed After debugging, I've found that the entire NodeForm appears to be submitted to the backend, and the only handler that is found is from some other field that uses ajax. In short 'updateSegmentSet' is never discovered as a submit handler. When I debug the original module based on block/blockforms, I do see the correct submit handler being discovered. Now in the latter case, of course a blockForm is submitted to the back end with the correct plugin. Given that this is basically a form within a form within a form, is there something special I have to do to get the custom submit handler to run? I've read a few things online e.g. the 'settings' key and '#tree' = true. EDIT The Ajax property looks like this:       '#ajax' =&gt; [         'callback' =&gt; [$this, 'updateSegmentSetAjax'],         'wrapper' =&gt; $wrapper_id,       ],    public function updateSegmentSetAjax(array &amp;$form, FormStateInterface $form_state) {     $button = $form_state-&gt;getTriggeringElement();     // Go one level up in the form, to the widgets container.     return NestedArray::getValue($form, array_slice($button['#array_parents'], 0, -2));   }  As best I can tell, this is never called either.
66183
I have a string that represents a non indented XML that I would like to pretty-print. For example:  &lt;root&gt;&lt;node/&gt;&lt;/root&gt;   should become:  &lt;root&gt;   &lt;node/&gt; &lt;/root&gt;   Syntax highlighting is not a requirement. To tackle the problem I first transform the XML to add carriage returns and white spaces and then use a  tag to output the XML. To add new lines and white spaces I wrote the following function:   function formatXml(xml) {     var formatted = '';     var reg = /(&gt;)(&lt;)(\/*)/g;     xml = xml.replace(reg, '$1\r\n$2$3');     var pad = 0;     jQuery.each(xml.split('\r\n'), function(index, node) {         var indent = 0;         if (node.match( /.+&lt;\/\w[^&gt;]*&gt;$/ )) {             indent = 0;         } else if (node.match( /^&lt;\/\w/ )) {             if (pad != 0) {                 pad -= 1;             }         } else if (node.match( /^&lt;\w[^&gt;]*[^\/]&gt;.*$/ )) {             indent = 1;         } else {             indent = 0;         }          var padding = '';         for (var i = 0; i &lt; pad; i++) {             padding += '  ';         }          formatted += padding + node + '\r\n';         pad += indent;     });      return formatted; }   I then call the function like this:  jQuery('pre.formatted-xml').text(formatXml('&lt;root&gt;&lt;node1/&gt;&lt;/root&gt;'));   This works perfectly fine for me but while I was writing the previous function I thought that there must be a better way. So my question is do you know of any better way given an XML string to pretty-print it in an html page? Any javascript frameworks and/or plugins that could do the job are welcome. My only requirement is this to be done on the client side.
73330
I'm in the process of retreiving some data from a xml file, it is actually a SSIS package file (dtsx).  I've read about using xmllint, however I'm having a hard time retrieving what I want.  I'd like to ask some helps from folks here.  This is what my xml looks like:  &lt;?xml version="1.0"?&gt; &lt;DTS:Executable xmlns:DTS="www.microsoft.com/SqlServer/Dts"   DTS:refId="Package"   DTS:CreationDate="7/22/2019 4:18:27 PM"   DTS:CreationName="Microsoft.Package"   DTS:CreatorComputerName="ADMIN-8DF005D47"   DTS:CreatorName="ADMIN-8DF005D47\Administrator"   DTS:DTSID="{8CCA1D42-642A-4932-AAEC-E02175A4B2DB}"   DTS:ExecutableType="Microsoft.Package"   DTS:LastModifiedProductVersion="15.0.2000.68"   DTS:LocaleID="1033"   DTS:ObjectName="HardestNestedWorkflow2"   DTS:PackageType="5"   DTS:VersionBuild="12"   DTS:VersionGUID="{FDD9B190-1A03-4A19-8794-FA86F4F46A93}"&gt;   &lt;DTS:Property     DTS:Name="PackageFormatVersion"&gt;8&lt;/DTS:Property&gt;   &lt;DTS:ConnectionManagers&gt;     &lt;DTS:ConnectionManager       DTS:refId="Package.ConnectionManagers[ADMIN-8DF005D47.AdventureWorks]"       DTS:CreationName="OLEDB"       DTS:DTSID="{A32A68DF-3D53-4057-AF80-1B8D524F82BC}"       DTS:ObjectName="ADMIN-8DF005D47.AdventureWorks"&gt;       &lt;DTS:ObjectData&gt;         &lt;DTS:ConnectionManager           DTS:ConnectionString="Data Source=ADMIN-8DF005D47;Initial Catalog=AdventureWorks;Provider=SQLNCLI11;Integrated Security=SSPI;Application Name=SSIS-HardestNestedWorkflow2-{A32A68DF-3D53-4057-AF80-1B8D524F82BC}ADMIN-8DF005D47.AdventureWorks;Auto Translate=False;" /&gt;       &lt;/DTS:ObjectData&gt;      &lt;!--snipped--&gt;      &lt;/DTS:ConnectionManager&gt;   &lt;/DTS:ConnectionManagers&gt; &lt;/DTS:Executable&gt;   I'm looking to get the value "8" out of this line  &lt;DTS:Property     DTS:Name="PackageFormatVersion"&gt;8&lt;/DTS:Property&gt;   so, what I did was to issue a command  xmllint --xpath "//*[local-name()='Executable']/*[local-ame()='Property']/text()" HardestNestedWorkflow2_latest.xml   .. and it was good, I was able to extract the value "8"  Now, I wanted to extract the value   Data Source=ADMIN-8DF005D47;Initial Catalog=AdventureWorks;Provider=SQLNCLI11;Integrated Security=SSPI;Application Name=SSIS-HardestNestedWorkflow2-{A32A68DF-3D53-4057-AF80-1B8D524F82BC}ADMIN-8DF005D47.AdventureWorks;Auto Translate=False;   I issued this statement  xmllint --xpath "//*[local-name()='Executable']/*[local-name()='ConnectionManagers']/*[local-name()='ConnectionManager']/*[local-name()='ObjectData']/*[local-name()='ConnectionManager']" HardestNestedWorkflow2_latest.xml   and it returned this   &lt;DTS:ConnectionManager DTS:ConnectionString="Data Source=ADMIN-8DF005D47;Initial Catalog=AdventureWorks;Provider=SQLNCLI11;Integrated Security=SSPI;Application Name=SSIS-HardestNestedWorkflow2-{A32A68DF-3D53-4057-AF80-1B8D524F82BC}ADMIN-8DF005D47.AdventureWorks;Auto Translate=False;"/&gt;   how can I omit the tags DTS:ConnectionManager DTS:ConnectionString?  I'm sorry I'm not much knowledgeable on using xmllint.  Thanks in Advance
64904
Why does the following gives the line I am searching:    grep '&lt;appointment-id internal:ref=1.2.3/&gt;' test.xml   OUTPUT is &lt;appointment-id internal:ref=1.2.3/&gt;     While the following breaks it into 2 lines?    a=($(grep '&lt;appointment-id internal:ref=1.2.3/&gt;' test.xml))   for i in "${a[@]}"; do       echo "checking $i"        grep  -n "$i" delete.xml done       The output is:     checking &lt;appointment-id checking internal:ref=1.2.3/&gt;   The file is:    &lt;note&gt;       &lt;to&gt;Jim&lt;/to&gt;       &lt;from&gt;John&lt;/from&gt;       &lt;heading&gt;Reminder&lt;/heading&gt;       &lt;body&gt;Some text&lt;/body&gt;       &lt;appointment-id internal:ref=1.2.3/&gt;  &lt;/note&gt;
57784
I'm working on a offline version of a website using jQuery and some xml files. I'm running in to a problem in jQuery when I do a $.ajax call on a xml file jQuery throws a error.  When I look at the error I can tell its loading the XML file because its in the error's responceText property. It seams to work just fine in Firefox.  This is how my call looks  $.ajax({     type: "GET",     url: "Modules/" + ModuleID + "/ModuleContent.xml",     dataType: "xml",     success: function(x) { xml = x; ProcessXML(); },     error: function(x) { alert(x.responceText); } });   When I run this on a web server it works just fine. Its only when I run it from the file its self when I have this problem.  Any ideas on how I can make this work in IE?  Edit: I found the answer to my problem.
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?
91776
I have created a shortcode that retrives and displays a form.The content of the attribute in HTML.   function check_my_login( $atts)     {          return '&lt;form action="" name="" method="post" enctype="multipart/form-data"&gt;                &lt;div class="form-group"&gt;                     &lt;label for="description"&gt;Project Description&lt;/label&gt;                     &lt;textarea name="p_description" placeholder="Project Description" class="form-control"&gt;&lt;?php if (isset($_POST['p_description']) &amp;&amp; $_POST['p_description'] != '') echo $_POST['p_description'] ?&gt;&lt;/textarea&gt;                 &lt;/div&gt;                  &lt;div class="form-group"&gt;                     &lt;label&gt;Project Attachment&lt;/label&gt;                     &lt;input type="file" name="p_attachment"&gt;                 &lt;/div&gt; &lt;/form&gt;';     }     add_shortcode( 'kentaUser', 'check_my_login' );   Now use this shortcode inside the Post/page.   Like this    &lt;div class='manage_page'&gt;[kentaUser]&lt;/div&gt;  But my shortcode content display out side the div.Display upper side in post/page content.  &lt;div class='manage_page'&gt;&lt;/div&gt;    Any one short out this problem.
23800
wondered if you could help me please? I have node in xml that is as followed  $LOG: 08880xbpnd $ fhdsafidsfsd df sd fsd f sd fsd  I was wondering is there anyway to make all the text go on to one line so that it then can be passsed through to a javascript function? so it would turn out like this   $LOG: 08880xbpnd $fhdsafidsfsddfsdfsdfsdfsd
9012
I'd like to make a click event fire on an &lt;input type="file"&gt; tag programmatically.  Just calling click() doesn't seem to do anything or at least it doesn't pop up a file selection dialog.  I've been experimenting with capturing events using listeners and redirecting the event, but I haven't been able to get that to actually perform the event like someone clicked on it.
85083
The following code helps me validate an XML file with an XSD schema.  XmlReaderSettings settings = new XmlReaderSettings(); settings.Schemas.Add(null, xsdFilePath); settings.ValidationType = ValidationType.Schema; settings.ValidationEventHandler += new System.Xml.Schema.ValidationEventHandler(settings_ValidationEventHandler); XmlDocument document = new XmlDocument(); document.Load(xmlFilePath); XmlReader rdr = XmlReader.Create(new StringReader(document.InnerXml), settings);  while (rdr.Read()) {  } isValid = true;   The ValidationEventHandler also tells me what the errors are, but doesn't tell me on 'where' or 'on which line' they are located. Is there any way to get the line number where the XML fails to be validated?
116031
I'm trying to write some PHP to upload a file to a folder on my webserver. Here's what I have:  &lt;?php     if ( !empty($_FILES['file']['tmp_name']) ) {         move_uploaded_file($_FILES['file']['tmp_name'], './' . $_FILES['file']['name']);         header('Location: http://www.mywebsite.com/dump/');         exit;     } ?&gt;  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"     "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"&gt; &lt;html&gt;     &lt;head&gt;         &lt;title&gt;Dump Upload&lt;/title&gt;     &lt;/head&gt;     &lt;body&gt;         &lt;h1&gt;Upload a File&lt;/h1&gt;         &lt;form action="upload.php" enctype="multipart/form-data" method="post"&gt;             &lt;input type="hidden" name="MAX_FILE_SIZE" value="1000000000" /&gt;             Select the File:&lt;br /&gt;&lt;input type="file" name="file" /&gt;&lt;br /&gt;             &lt;input type="submit" value="Upload" /&gt;         &lt;/form&gt;     &lt;/body&gt; &lt;/html&gt;   I'm getting these errors:     Warning: move_uploaded_file(./test.txt) [function.move-uploaded-file]: failed to open stream: Permission denied in E:\inetpub\vhosts\mywebsite.com\httpdocs\dump\upload.php on line 3      Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\WINDOWS\Temp\phpA30E.tmp' to './test.txt' in E:\inetpub\vhosts\mywebsite.com\httpdocs\dump\upload.php on line 3      Warning: Cannot modify header information - headers already sent by (output started at E:\inetpub\vhosts\mywebsite.com\httpdocs\dump\upload.php:3) in E:\inetpub\vhosts\mywebsite.com\httpdocs\dump\upload.php on line 4   PHP version 4.4.7 Running IIS on a Windows box. This particular file/folder has 777 permissions.  Any ideas?
51051
How can I change an attribute of an element in an XML file, using C#?
76521
I need to validate an XML string (and not a file) against a DTD description file.   How can that be done in python?
20913
I'm trying to retrieve the translations in translation workbench to add to Stash. My sample .xml file is below.  &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;Package xmlns="http://soap.sforce.com/2006/04/metadata"&gt; &lt;types&gt;     &lt;members&gt;Sample_Object__c-es_CO&lt;/members&gt;     &lt;name&gt;CustomObjectTranslation&lt;/name&gt; &lt;/types&gt;     &lt;version&gt;37.0&lt;/version&gt; &lt;/Package&gt;   I am able to successfully retrieve the object, but the file does not contain any of the translations that I have added. I have verified that I am using the correct sandbox, I verified the object name, I verified that I added the translations in my sandbox, but still no luck.  The sample output in the file is below:  &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;CustomObjectTranslation xmlns="http://soap.sforce.com/2006/04/metadata"&gt;     &lt;caseValues&gt;         &lt;plural&gt;false&lt;/plural&gt;         &lt;value&gt;&lt;!-- Sample Object --&gt;&lt;/value&gt;     &lt;/caseValues&gt;     &lt;caseValues&gt;         &lt;plural&gt;true&lt;/plural&gt;         &lt;value&gt;&lt;!-- Sample Object --&gt;&lt;/value&gt;     &lt;/caseValues&gt;     &lt;gender&gt;&lt;!-- Feminine --&gt;&lt;/gender&gt;     &lt;nameFieldLabel&gt;&lt;!-- Sample Object Name --&gt;&lt;/nameFieldLabel&gt; &lt;/CustomObjectTranslation&gt;