Top Menu

Showing posts with label XML. Show all posts
Showing posts with label XML. Show all posts

Friday, February 13, 2015

HTTP Request with Javascript

<script type="text/javascript">

var oReq = new ActiveXObject("MSXML2.XMLHTTP.3.0");

function handler()
{
    if (oReq.readyState == 4 /* complete */) {
        if (oReq.status == 200) {
            document.getElementById("myDiv").innerText = oReq.responseText;
        }
    }
}

function SendRequest()
{
    var vURL = "http://IdolApp:12345/data/data.xml";

    if (oReq != null) {
        oReq.open("GET", vURL, true);
        oReq.onreadystatechange = handler;
        oReq.send();
    }
    else {
        window.console.log("AJAX (XMLHTTP) not supported.");
    }
}

</script>
<input type="button" id="btnSubmit" value="Go" onclick="SendRequest()"/>
<br/>
<div id="myDiv" >:o)</div>
Ref: https://msdn.microsoft.com/en-us/library/ie/ms535874(v=vs.85).aspx

Note:
Initialize the oReq with following to make it IE and Chrome compatible:
var oReq;

if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
 oReq=new XMLHttpRequest();
}
else
{// code for IE6, IE5
 oReq=new ActiveXObject("Microsoft.XMLHTTP");
}

Thursday, December 4, 2014

Reading XML with PowerShell

Here is an example of accessing XML data via PowerShell:

Script:
$xmlDocument = [xml] @"
<catalog>
   <book id="101">
      <author>Author1</author>
      <title>Title1</title>
      <genre>Genere1</genre>
      <price>45.95</price>
      <publish_date>2000-10-01</publish_date>
      <description>This is a description1.</description>
   </book>
   <book id="101">
      <author>Author2</author>
      <title>Title2</title>
      <genre>Genere2</genre>
      <price>75.99</price>
      <publish_date>1998-7-15</publish_date>
      <description>This is a description2.</description>
   </book>
</catalog>
"@

$xmlDocument.catalog.book | Select-Object -Property author, title, price

Result:
PS C:\Users\tnaveed\Desktop> C:\Users\tnaveed\Desktop\CheckUser.ps1

author                         title                         price                        
------                         -----                         -----                        
Author1                        Title1                        45.95                        
Author2                        Title2                        75.99                        

Tuesday, May 7, 2013

PowerShell - Saving Site and Sub-site in XML file

Scenario:
I had a requirement today to get all personal sites (site collections) and the blog sites (sub-sites) under MySite Host Site and save in an XML file. 

Following powershell script does the trick for a web application: 

PowerShell Script:
Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

$webs =  Get-SPSite -webapplication "http://mysite.domain.com"
$FilePath = "C:\Temp\MySites.xml"

Write-Host Getting all MySites...

$xml = "<PersonalSite>"
Foreach ($oneweb in $webs)
{
    $web = $oneweb.RootWeb

    if ($web.WebTemplate -eq "SPSMSITEHOST" -Or $web.WebTemplate -eq "SPSPERS")
    {
        $xml = $xml + "<Site>"
        $xml = $xml + "<MySite>" + $oneweb.URL + "</MySite>"
        Write-Host "Processing:" $oneweb.URL
            
        $spWeb = Get-SPweb $oneweb.URL
        foreach($subSite in $spWeb.Webs)
        {
            if ($subSite.WebTemplate -eq "BLOG")
            {
                $xml = $xml + "<Blog>" + $subSite.URL + "</Blog>"
            }
        }
        $spWeb.Dispose()

        $xml = $xml + "</Site>"
    }    
}
$xml = $xml + "</PersonalSite>"
#Write-Host $xml

$xml | out-File -FilePath $FilePath

Write-Host "XML file has been generate."
Write-Host "Press anyke to continue..."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

Result (MySites.xml):
<PersonalSite>
  <Site>
    <MySite>http://mysite.domain.com/my</MySite>
  </Site>
  <Site>
    <MySite>http://mysite.domain.com/my/personal/mjackson</MySite>
    <Blog>http://mysite.domain.com/my/personal/mjackson/Blog</Blog>
  </Site>
  <Site>
    <MySite>http://mysite.domain.com/my/personal/jdoe</MySite>
    <Blog>http://mysite.domain.com/my/personal/jdoe/Blog</Blog>
  </Site>
  <Site>
    <MySite>http://mysite.domain.com/my/personal/sman</MySite>
    <Blog>http://mysite.domain.com/my/personal/sman/Blog</Blog>
  </Site>
</PersonalSite>

Tuesday, November 2, 2010

View All XML Data via XSLT


Some times we have to debug the XSLT for a WebPart (which generates XML data as output e.g. Search Core Results WebPart in MOSS) to manipulate the results. The first step of XSLT debugging is to see if the generated XML is valid and have all the necessary data.

Following is the code XSLT snippit to display all the XML elements:





<xsl:copy-of select="*"/>





Official SharePoint Documentation

I have recently contributed to the official SharePoint documentation for developement. Check it out here: https://docs.microsoft.com/en-us...