2009-12-10 3 views
1

저는 개발자가 아닙니다.자동 생성 된 GUID 집합을 동적으로 생성 된 도구로 대체하는 도구가 있습니까?

각 GUID가 할당 된 수백 개의 리소스를 복제하려면 XML 파일을 해킹해야합니다. 태그에서 찾은 각 GUID를 동적으로 생성 된 것으로 대체하여 전체 파일을 구문 분석 할 수있는 방법이 있습니까?

기본적으로 모든 UniqueID 태그 (ContentUniqueID 태그 제외)에는 새 GUID가 필요합니다.

<root xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'> 
    <Name>[redacted]</Name> 
    <UniqueId>7a136c33-3ea8-4f99-8f99-bbe411972203</UniqueId> 
    <Enabled>true</Enabled> 
    <Behavior>EmptyOnly</Behavior> 
    <Subscriptions /> 
    <ScheduledFormatTemplates> 
    <ScheduledFormatTemplate> 
     <Name>[redacted]</Name> 
     <UniqueId>1cfaba3e-bfd5-4d2f-a1df-14020ad2f7da</UniqueId> 
     <ContentUniqueId>67c58741-fe1b-4c15-8dc0-8b4c01f6f18f</ContentUniqueId> 
     <ScheduledContents> 
     <ScheduledContent xsi:type="SFTR"> 
      <Name>[redacted]</Name> 
      <UniqueId>b4a60646-b62b-43e7-b2a2-7d37875ab33f</UniqueId> 
      <ContentUniqueId>ba634a97-9faf-4bfa-a9b4-d8a2475b82e6</ContentUniqueId> 
      <ScheduledContents> 
      <ScheduledContent> 
       <Name>[redacted]</Name> 
       <UniqueId>6f8e6e6c-1f94-4caa-8730-6859448138eb</UniqueId> 
       <ContentUniqueId>938b0a24-4043-4a16-bc2d-25dbdb21a659</ContentUniqueId> 
      </ScheduledContent> 
      </ScheduledContents> 
     </ScheduledContent> 
     </ScheduledContents> 
    </ScheduledFormatTemplate> 
    </ScheduledFormatTemplates> 
</root> 
+0

잘 예, 어떤 도구/언어는 사용하여에이 찾고 있습니까? – brendan

답변

1

않는 웹 기반 도구는이 here

+0

신경 쓰지 마라, 나는 이것을 사용하지 않을 것이다. 내가 찾은 모든 지침을 대체합니다. – BigJoe714

2

는 그와 같은 도구의 모르겠지만, 개발자 10 ~ 15 분 만에이 작업을 수행 PowerShell 스크립트, 또는 펄 스크립트를 생성 할 수 있도록해야한다.

XML 파일의 샘플을 게시하면 다른 사람이 작업 코드를 게시 할 수도 있습니다. 질문을 Q라는 문구로 사용하면 더 많은 사람들이 응답하게됩니다. XML 파일의 복잡성에 따라 스크립트의 줄이 10 줄 정도 될 수 있습니다.


이 같은 다른 요구 사항이 있다면 - 당신은 모두가 특정 범위에서 선택 될 수있는 새로운 GUID를 원하는 경우 - 여전히 가능하고 간단 될 것입니다,하지만 당신은 모든 요구 사항을 명시해야합니다.


## 
## ReplaceGuids.ps1 
## 
## Reads an XML document, and emits an output doc. The output replaces 
## the Text value of each node in the input with LocalName="UniqueId", with 
## a new Guid. 
## 
## Thu, 10 Dec 2009 12:06 
## 


# Create the XmlReader 
$xr = [system.Xml.XmlReader]::Create("c:\data\Doug.xml") 
# Create the XmlWriter 
$sw = New-Object System.IO.StringWriter 
$xw = New-Object System.Xml.XmlTextWriter $sw 
$xw.Formatting = "indented" 
$xw.Indentation = 2 

$elementName = "" 

# loop over each element in XmlReader 
while ($true) { 
    if ($xr.Read() -eq $false) { break; } 
    switch ($xr.NodeType.ToString()) 
    { 
    "Element" { 
     $xw.WriteStartElement($xr.Name) 
     $xw.WriteAttributes($xr, $false) 
     if ($xr.IsEmptyElement) { $xw.WriteEndElement(); $elementName = ""; } 
     else {$elementName = $xr.LocalName; } 
    } 

    "EndElement" { 
     $xw.WriteEndElement() 
     $elementName = "" 
    } 

    "Text" { 
     if ($elementName -eq "UniqueId") { 
     $guid = [System.Guid]::NewGuid() 
     $xw.WriteValue($guid.ToString()) 
     } else { 
     $xw.WriteValue($xr.Value) 
     } 
    } 
    } 
} 

$xr.Close() 
$xw.Flush() 
$sw.Flush() 
Write-Output $sw.ToString() 
+0

다른 요구 사항은 없습니다. 그들은 단지 서로 구별 될 필요가 있습니다. 어쩌면 사람들이 자주해야 할 일이라고 생각했습니다. –

+0

샘플 코드를 게시 해 드리겠습니다. 기본적으로 문서의 태그는 모두 새롭고 고유 한 GUID로 대체되어야합니다. –

+0

저는 Sysadmin PowerShell을 사용하지만 Developer PowerShell은 사용하지 않습니다. 따라서이 기능을 수행하는 좋은 방법이라면 나에게 말하는 내용을 따라갈 수 있습니다. –

관련 문제