使用外部实体将XML文档分为两部分 [英] Breakdown an XML document into two using external entity
问题描述
我想将xml文档分解为两个.这基本上是通过访问第二个xml文件作为外部实体.原始的完整文档如下所示:
I want to breakdown an xml document into two. This is basically by accessing the second xml file as external entity. Originally the full document looks as follows:
<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>
<par1>Don''t forget me this weekend!</par1>
</body>
</note>
该文档以文件名
this document is saved with file name
mymessage.txt
保存,我可以通过
从powershell中访问par1标记的内容.
and i can access the content of par1 tag from powershell as
$xmlFileName = ''E:\mymessage.txt''
[xml]$xmlDoc = Get-Content $xmlFileName
Write-Host $xmlDoc.note.body.par1
效果很好.
我尝试过的事情:
现在我想将文件分成两部分,然后将正文部分放在名为
This works fine.
What I have tried:
Now i want to split the file into two and I put the body part in separate file called
mymessage_body.txt
的单独文件中,它看起来
and it looks
<?xml version="1.0" encoding="UTF-8"?>
<DOCTYPE body [
<!ELEMENT body (par1)>
<!ELEMENT par1 (#PCDATA)>
]>
<body>
<par1>Don''t forget me this weekend!</par1>
</body>
同样,我将标题部分放在另一个文件中(称为
Similarly i put the header part in another file (called
mymessage_header.txt
),它看起来
) and it looks
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE note [
<!ELEMENT note ANY>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ENTITY body SYSTEM "mymessage_body.txt">
]>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
&body;
</note>
现在,我尝试从powershell访问par1的内容,如上图所示,它不返回任何内容.我想知道外部实体是否正确加载.您能提出您的建议解决这个问题吗?谢谢!
Now i tried to access the content of par1 from powershell as shown above it returns nothing. I want to know weather the external entity is properly loaded or not. Would you please forward your suggestion in resolving this? Thanks!
推荐答案
xmlFileName =''E:\ mymessage.txt'' [xml]
xmlFileName = ''E:\mymessage.txt'' [xml]
xmlDoc =获取内容
xmlDoc = Get-Content
xmlFileName 写主机
xmlFileName Write-Host
这篇关于使用外部实体将XML文档分为两部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!